This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +30
-2
lines changed
2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -238,8 +238,9 @@ LocationUrl.prototype = LocationHashbangUrl.prototype = {
238
238
return this . $$url ;
239
239
240
240
var match = PATH_MATCH . exec ( url ) ;
241
- this . path ( decodeURIComponent ( match [ 1 ] || '' ) ) . search ( match [ 3 ] || '' )
242
- . hash ( match [ 5 ] || '' , replace ) ;
241
+ if ( match [ 1 ] ) this . path ( decodeURIComponent ( match [ 1 ] ) ) ;
242
+ if ( match [ 2 ] || match [ 1 ] ) this . search ( match [ 3 ] || '' ) ;
243
+ this . hash ( match [ 5 ] || '' , replace ) ;
243
244
244
245
return this ;
245
246
} ,
Original file line number Diff line number Diff line change @@ -95,6 +95,33 @@ describe('$location', function() {
95
95
} ) ;
96
96
97
97
98
+ it ( 'url() should change only hash when no search and path specified' , function ( ) {
99
+ url . url ( '#some-hash' ) ;
100
+
101
+ expect ( url . hash ( ) ) . toBe ( 'some-hash' ) ;
102
+ expect ( url . url ( ) ) . toBe ( '/path/b?search=a&b=c&d#some-hash' ) ;
103
+ expect ( url . absUrl ( ) ) . toBe ( 'http://www.domain.com:9877/path/b?search=a&b=c&d#some-hash' ) ;
104
+ } ) ;
105
+
106
+
107
+ it ( 'url() should change only search and hash when no path specified' , function ( ) {
108
+ url . url ( '?a=b' ) ;
109
+
110
+ expect ( url . search ( ) ) . toEqual ( { a : 'b' } ) ;
111
+ expect ( url . hash ( ) ) . toBe ( '' ) ;
112
+ expect ( url . path ( ) ) . toBe ( '/path/b' ) ;
113
+ } ) ;
114
+
115
+
116
+ it ( 'url() should reset search and hash when only path specified' , function ( ) {
117
+ url . url ( '/new/path' ) ;
118
+
119
+ expect ( url . path ( ) ) . toBe ( '/new/path' ) ;
120
+ expect ( url . search ( ) ) . toEqual ( { } ) ;
121
+ expect ( url . hash ( ) ) . toBe ( '' ) ;
122
+ } ) ;
123
+
124
+
98
125
it ( 'replace should set $$replace flag and return itself' , function ( ) {
99
126
expect ( url . $$replace ) . toBe ( false ) ;
100
127
You can’t perform that action at this time.
0 commit comments