Skip to content

Commit 6baaa6c

Browse files
nornagonmjackson
authored andcommitted
Run path components through encode/decodeURIComponent
1 parent 4759961 commit 6baaa6c

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

modules/DOMUtils.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ export function replaceHashPath(path) {
1818
}
1919

2020
export function getWindowPath() {
21-
return decodeURI(
22-
window.location.pathname + window.location.search
23-
);
21+
return window.location.pathname + window.location.search;
2422
}
2523

2624
export function getWindowScrollPosition() {

modules/URLUtils.js

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

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

121123
if (captureRemaining) {
122124
remainingPathname = paramValues.pop();
@@ -191,7 +193,7 @@ export function formatPattern(pattern, params) {
191193
);
192194

193195
if (paramValue != null)
194-
pathname += paramValue;
196+
pathname += encodeURIComponent(paramValue);
195197
} else {
196198
pathname += token;
197199
}

modules/__tests__/URLUtils-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,13 @@ describe('formatPattern', function () {
245245

246246
describe('and some params have special URL encoding', function () {
247247
it('returns the correct path', function () {
248-
expect(formatPattern(pattern, { id: 'one, two' })).toEqual('comments/one, two/edit');
248+
expect(formatPattern(pattern, { id: 'one, two' })).toEqual('comments/one%2C%20two/edit');
249249
});
250250
});
251251

252252
describe('and a param has a forward slash', function () {
253253
it('preserves the forward slash', function () {
254-
expect(formatPattern(pattern, { id: 'the/id' })).toEqual('comments/the/id/edit');
254+
expect(formatPattern(pattern, { id: 'the/id' })).toEqual('comments/the%2Fid/edit');
255255
});
256256
});
257257

0 commit comments

Comments
 (0)