This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +17
-2
lines changed
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -416,7 +416,7 @@ LocationHashbangInHtml5Url.prototype =
416
416
* @return {string } path
417
417
*/
418
418
path : locationGetterSetter ( '$$path' , function ( path ) {
419
- path = path . toString ( ) ;
419
+ path = path ? path . toString ( ) : '' ;
420
420
return path . charAt ( 0 ) == '/' ? path : '/' + path ;
421
421
} ) ,
422
422
@@ -513,7 +513,7 @@ LocationHashbangInHtml5Url.prototype =
513
513
* @return {string } hash
514
514
*/
515
515
hash : locationGetterSetter ( '$$hash' , function ( hash ) {
516
- return hash . toString ( ) ;
516
+ return hash ? hash . toString ( ) : '' ;
517
517
} ) ,
518
518
519
519
/**
Original file line number Diff line number Diff line change @@ -142,6 +142,14 @@ describe('$location', function() {
142
142
expect ( url . absUrl ( ) ) . toBe ( 'http://www.domain.com:9877/1?search=a&b=c&d#hash' ) ;
143
143
} ) ;
144
144
145
+
146
+ it ( 'path() should set to empty path on null value' , function ( ) {
147
+ url . path ( '/foo' ) ;
148
+ expect ( url . path ( ) ) . toBe ( '/foo' ) ;
149
+ url . path ( null ) ;
150
+ expect ( url . path ( ) ) . toBe ( '/' ) ;
151
+ } ) ;
152
+
145
153
it ( 'search() should accept string' , function ( ) {
146
154
url . search ( 'x=y&c' ) ;
147
155
expect ( url . search ( ) ) . toEqual ( { x : 'y' , c : true } ) ;
@@ -233,6 +241,13 @@ describe('$location', function() {
233
241
} ) ;
234
242
235
243
244
+ it ( 'hash() should accept null parameter' , function ( ) {
245
+ url . hash ( null ) ;
246
+ expect ( url . hash ( ) ) . toBe ( '' ) ;
247
+ expect ( url . absUrl ( ) ) . toBe ( 'http://www.domain.com:9877/path/b?search=a&b=c&d' ) ;
248
+ } ) ;
249
+
250
+
236
251
it ( 'url() should change the path, search and hash' , function ( ) {
237
252
url . url ( '/some/path?a=b&c=d#hhh' ) ;
238
253
expect ( url . url ( ) ) . toBe ( '/some/path?a=b&c=d#hhh' ) ;
You can’t perform that action at this time.
0 commit comments