@@ -272,6 +272,8 @@ describe("UrlMatcher", function () {
272272 expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { param1 : undefined } ) ;
273273 $location . url ( "/foo?param1=bar" ) ;
274274 expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { param1 : 'bar' } ) ; // auto unwrap
275+ $location . url ( "/foo?param1=" ) ;
276+ expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { param1 : undefined } ) ;
275277 $location . url ( "/foo?param1=bar¶m1=baz" ) ;
276278 if ( angular . isArray ( $location . search ( ) ) ) // conditional for angular 1.0.8
277279 expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { param1 : [ 'bar' , 'baz' ] } ) ;
@@ -334,6 +336,29 @@ describe("UrlMatcher", function () {
334336 expect ( m . format ( { "param1[]" : [ 'bar' , 'baz' ] } ) ) . toBe ( "/foo?param1[]=bar¶m1[]=baz" ) ;
335337 } ) ) ;
336338
339+ // Test for issue #2222
340+ it ( "should return default value, if query param is missing." , inject ( function ( $location ) {
341+ var m = new UrlMatcher ( '/state?param1¶m2¶m3¶m5' , {
342+ params : {
343+ param1 : 'value1' ,
344+ param2 : { array : true , value : [ 'value2' ] } ,
345+ param3 : { array : true , value : [ ] } ,
346+ param5 : { array : true , value : function ( ) { return [ ] ; } }
347+ }
348+ } ) ;
349+
350+ var parsed = m . exec ( "/state" ) ;
351+ var expected = {
352+ "param1" : 'value1' ,
353+ "param2" : [ 'value2' ] ,
354+ "param3" : [ ] ,
355+ "param5" : [ ]
356+ } ;
357+
358+ expect ( parsed ) . toEqualData ( expected )
359+ expect ( m . params . $$values ( parsed ) ) . toEqualData ( expected ) ;
360+ } ) ) ;
361+
337362 it ( "should not be wrapped by ui-router into an array if array: false" , inject ( function ( $location ) {
338363 var m = new UrlMatcher ( '/foo?param1' , { params : { param1 : { array : false } } } ) ;
339364
0 commit comments