@@ -16,7 +16,23 @@ function encodePath(path) {
16
16
i = segments . length ;
17
17
18
18
while ( i -- ) {
19
- segments [ i ] = encodeUriSegment ( segments [ i ] ) ;
19
+ // decode forward slashes to prevent them from being double encoded
20
+ segments [ i ] = encodeUriSegment ( segments [ i ] . replace ( / % 2 F / g, '/' ) ) ;
21
+ }
22
+
23
+ return segments . join ( '/' ) ;
24
+ }
25
+
26
+ function decodePath ( path , html5Mode ) {
27
+ var segments = path . split ( '/' ) ,
28
+ i = segments . length ;
29
+
30
+ while ( i -- ) {
31
+ segments [ i ] = decodeURIComponent ( segments [ i ] ) ;
32
+ if ( html5Mode ) {
33
+ // encode forward slashes to prevent them from being mistaken for path separators
34
+ segments [ i ] = segments [ i ] . replace ( / \/ / g, '%2F' ) ;
35
+ }
20
36
}
21
37
22
38
return segments . join ( '/' ) ;
@@ -31,7 +47,7 @@ function parseAbsoluteUrl(absoluteUrl, locationObj) {
31
47
}
32
48
33
49
var DOUBLE_SLASH_REGEX = / ^ \s * [ \\ / ] { 2 , } / ;
34
- function parseAppUrl ( url , locationObj ) {
50
+ function parseAppUrl ( url , locationObj , html5Mode ) {
35
51
36
52
if ( DOUBLE_SLASH_REGEX . test ( url ) ) {
37
53
throw $locationMinErr ( 'badpath' , 'Invalid url "{0}".' , url ) ;
@@ -42,8 +58,8 @@ function parseAppUrl(url, locationObj) {
42
58
url = '/' + url ;
43
59
}
44
60
var match = urlResolve ( url ) ;
45
- locationObj . $$ path = decodeURIComponent ( prefixed && match . pathname . charAt ( 0 ) === '/' ?
46
- match . pathname . substring ( 1 ) : match . pathname ) ;
61
+ var path = prefixed && match . pathname . charAt ( 0 ) === '/' ? match . pathname . substring ( 1 ) : match . pathname ;
62
+ locationObj . $$path = decodePath ( path , html5Mode ) ;
47
63
locationObj . $$search = parseKeyValue ( match . search ) ;
48
64
locationObj . $$hash = decodeURIComponent ( match . hash ) ;
49
65
@@ -118,7 +134,7 @@ function LocationHtml5Url(appBase, appBaseNoFile, basePrefix) {
118
134
appBaseNoFile ) ;
119
135
}
120
136
121
- parseAppUrl ( pathUrl , this ) ;
137
+ parseAppUrl ( pathUrl , this , true ) ;
122
138
123
139
if ( ! this . $$path ) {
124
140
this . $$path = '/' ;
@@ -221,7 +237,7 @@ function LocationHashbangUrl(appBase, appBaseNoFile, hashPrefix) {
221
237
}
222
238
}
223
239
224
- parseAppUrl ( withoutHashUrl , this ) ;
240
+ parseAppUrl ( withoutHashUrl , this , false ) ;
225
241
226
242
this . $$path = removeWindowsDriveName ( this . $$path , withoutHashUrl , appBase ) ;
227
243
@@ -406,7 +422,7 @@ var locationPrototype = {
406
422
}
407
423
408
424
var match = PATH_MATCH . exec ( url ) ;
409
- if ( match [ 1 ] || url === '' ) this . path ( decodeURIComponent ( match [ 1 ] ) ) ;
425
+ if ( match [ 1 ] || url === '' ) this . path ( decodeURI ( match [ 1 ] ) ) ;
410
426
if ( match [ 2 ] || match [ 1 ] || url === '' ) this . search ( match [ 3 ] || '' ) ;
411
427
this . hash ( match [ 5 ] || '' ) ;
412
428
0 commit comments