@@ -297,6 +297,8 @@ describe("UrlMatcher", function () {
297
297
expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { param1 : undefined } ) ;
298
298
$location . url ( "/foo?param1=bar" ) ;
299
299
expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { param1 : 'bar' } ) ; // auto unwrap
300
+ $location . url ( "/foo?param1=" ) ;
301
+ expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { param1 : undefined } ) ;
300
302
$location . url ( "/foo?param1=bar¶m1=baz" ) ;
301
303
if ( angular . isArray ( $location . search ( ) ) ) // conditional for angular 1.0.8
302
304
expect ( m . exec ( $location . path ( ) , $location . search ( ) ) ) . toEqual ( { param1 : [ 'bar' , 'baz' ] } ) ;
@@ -359,6 +361,36 @@ describe("UrlMatcher", function () {
359
361
expect ( m . format ( { "param1[]" : [ 'bar' , 'baz' ] } ) ) . toBe ( "/foo?param1[]=bar¶m1[]=baz" ) ;
360
362
} ) ) ;
361
363
364
+ // Test for issue #2222
365
+ it ( "should return default value, if query param is missing." , inject ( function ( $location ) {
366
+ var m = new UrlMatcher ( '/state?param1¶m2¶m3¶m5' , {
367
+ params : {
368
+ param1 : 'value1' ,
369
+ param2 : { array : true , value : [ 'value2' ] } ,
370
+ param3 : { array : true , value : [ ] } ,
371
+ param5 : { array : true , value : function ( ) { return [ ] ; } }
372
+ }
373
+ } ) ;
374
+
375
+ var expected = {
376
+ "param1" : 'value1' ,
377
+ "param2" : [ 'value2' ] ,
378
+ "param3" : [ ] ,
379
+ "param5" : [ ]
380
+ } ;
381
+
382
+ // Parse url to get Param.value()
383
+ var parsed = m . exec ( "/state" ) ;
384
+ expect ( parsed ) . toEqualData ( expected ) ;
385
+
386
+ // Pass again through Param.value() for normalization (like transitionTo)
387
+ var paramDefs = m . parameters ( ) ;
388
+ var values = common . map ( parsed , function ( val , key ) {
389
+ return common . find ( paramDefs , function ( def ) { return def . id === key } ) . value ( val ) ;
390
+ } ) ;
391
+ expect ( values ) . toEqualData ( expected ) ;
392
+ } ) ) ;
393
+
362
394
it ( "should not be wrapped by ui-router into an array if array: false" , inject ( function ( $location ) {
363
395
var m = new UrlMatcher ( '/foo?param1' , { params : { param1 : { array : false } } } ) ;
364
396
0 commit comments