This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -416,7 +416,7 @@ LocationHashbangInHtml5Url.prototype =
416416 * @return {string } path
417417 */
418418 path : locationGetterSetter ( '$$path' , function ( path ) {
419- path = path . toString ( ) ;
419+ path = path ? path . toString ( ) : '' ;
420420 return path . charAt ( 0 ) == '/' ? path : '/' + path ;
421421 } ) ,
422422
@@ -513,7 +513,7 @@ LocationHashbangInHtml5Url.prototype =
513513 * @return {string } hash
514514 */
515515 hash : locationGetterSetter ( '$$hash' , function ( hash ) {
516- return hash . toString ( ) ;
516+ return hash ? hash . toString ( ) : '' ;
517517 } ) ,
518518
519519 /**
Original file line number Diff line number Diff line change @@ -142,6 +142,14 @@ describe('$location', function() {
142142 expect ( url . absUrl ( ) ) . toBe ( 'http://www.domain.com:9877/1?search=a&b=c&d#hash' ) ;
143143 } ) ;
144144
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+
145153 it ( 'search() should accept string' , function ( ) {
146154 url . search ( 'x=y&c' ) ;
147155 expect ( url . search ( ) ) . toEqual ( { x : 'y' , c : true } ) ;
@@ -233,6 +241,13 @@ describe('$location', function() {
233241 } ) ;
234242
235243
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+
236251 it ( 'url() should change the path, search and hash' , function ( ) {
237252 url . url ( '/some/path?a=b&c=d#hhh' ) ;
238253 expect ( url . url ( ) ) . toBe ( '/some/path?a=b&c=d#hhh' ) ;
You can’t perform that action at this time.
0 commit comments