Skip to content

Commit 41bd525

Browse files
committed
[fixed] Properly escape splats
1 parent 6baaa6c commit 41bd525

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

modules/DOMUtils.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
export var canUseDOM = !!(
2-
(typeof window !== 'undefined' &&
3-
window.document && window.document.createElement)
2+
typeof window !== 'undefined' && window.document && window.document.createElement
43
);
54

65
export function getHashPath() {
7-
return decodeURI(
8-
// We can't use window.location.hash here because it's not
9-
// consistent across browsers - Firefox will pre-decode it!
10-
window.location.href.split('#')[1] || ''
11-
);
6+
// We can't use window.location.hash here because it's not
7+
// consistent across browsers - Firefox will pre-decode it!
8+
return window.location.href.split('#')[1] || '';
129
}
1310

1411
export function replaceHashPath(path) {

modules/URLUtils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ export function matchPattern(pattern, pathname) {
116116

117117
var remainingPathname, paramValues;
118118
if (match != null) {
119-
paramValues = Array.prototype.slice.call(match, 1).map(
120-
(v) => v != null ? decodeURIComponent(v) : v
121-
);
119+
paramValues = Array.prototype.slice.call(match, 1).map(function (v) {
120+
return v != null ? decodeURIComponent(v) : v;
121+
});
122122

123123
if (captureRemaining) {
124124
remainingPathname = paramValues.pop();
@@ -177,7 +177,7 @@ export function formatPattern(pattern, params) {
177177
);
178178

179179
if (paramValue != null)
180-
pathname += paramValue;
180+
pathname += encodeURIComponent(paramValue);
181181
} else if (token === '(') {
182182
parenCount += 1;
183183
} else if (token === ')') {

modules/__tests__/URLUtils-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe('formatPattern', function () {
264264

265265
describe('when a pattern has one splat', function () {
266266
it('returns the correct path', function () {
267-
expect(formatPattern('/a/*/d', { splat: 'b/c' })).toEqual('/a/b/c/d');
267+
expect(formatPattern('/a/*/d', { splat: 'b/c' })).toEqual('/a/b%2Fc/d');
268268
});
269269
});
270270

0 commit comments

Comments
 (0)