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 @@ -391,7 +391,7 @@ LocationHashbangInHtml5Url.prototype =
391
391
* @return {string } path
392
392
*/
393
393
path : locationGetterSetter ( '$$path' , function ( path ) {
394
- path = path . toString ( ) ;
394
+ path = path ? path . toString ( ) : '' ;
395
395
return path . charAt ( 0 ) == '/' ? path : '/' + path ;
396
396
} ) ,
397
397
@@ -488,7 +488,7 @@ LocationHashbangInHtml5Url.prototype =
488
488
* @return {string } hash
489
489
*/
490
490
hash : locationGetterSetter ( '$$hash' , function ( hash ) {
491
- return hash . toString ( ) ;
491
+ return hash ? hash . toString ( ) : '' ;
492
492
} ) ,
493
493
494
494
/**
Original file line number Diff line number Diff line change @@ -93,6 +93,14 @@ describe('$location', function() {
93
93
expect ( url . absUrl ( ) ) . toBe ( 'http://www.domain.com:9877/1?search=a&b=c&d#hash' ) ;
94
94
} ) ;
95
95
96
+
97
+ it ( 'path() should set to empty path on null value' , function ( ) {
98
+ url . path ( '/foo' ) ;
99
+ expect ( url . path ( ) ) . toBe ( '/foo' ) ;
100
+ url . path ( null ) ;
101
+ expect ( url . path ( ) ) . toBe ( '/' ) ;
102
+ } ) ;
103
+
96
104
it ( 'search() should accept string' , function ( ) {
97
105
url . search ( 'x=y&c' ) ;
98
106
expect ( url . search ( ) ) . toEqual ( { x : 'y' , c : true } ) ;
@@ -184,6 +192,13 @@ describe('$location', function() {
184
192
} ) ;
185
193
186
194
195
+ it ( 'hash() should accept null parameter' , function ( ) {
196
+ url . hash ( null ) ;
197
+ expect ( url . hash ( ) ) . toBe ( '' ) ;
198
+ expect ( url . absUrl ( ) ) . toBe ( 'http://www.domain.com:9877/path/b?search=a&b=c&d' ) ;
199
+ } ) ;
200
+
201
+
187
202
it ( 'url() should change the path, search and hash' , function ( ) {
188
203
url . url ( '/some/path?a=b&c=d#hhh' ) ;
189
204
expect ( url . url ( ) ) . toBe ( '/some/path?a=b&c=d#hhh' ) ;
You can’t perform that action at this time.
0 commit comments