Skip to content

Commit

Permalink
Run path components through encode/decodeURIComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon authored and mjackson committed Jun 19, 2015
1 parent 4759961 commit 6baaa6c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 1 addition & 3 deletions modules/DOMUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export function replaceHashPath(path) {
}

export function getWindowPath() {
return decodeURI(
window.location.pathname + window.location.search
);
return window.location.pathname + window.location.search;
}

export function getWindowScrollPosition() {
Expand Down
6 changes: 4 additions & 2 deletions modules/URLUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ export function matchPattern(pattern, pathname) {

var remainingPathname, paramValues;
if (match != null) {
paramValues = Array.prototype.slice.call(match, 1);
paramValues = Array.prototype.slice.call(match, 1).map(
(v) => v != null ? decodeURIComponent(v) : v
);

if (captureRemaining) {
remainingPathname = paramValues.pop();
Expand Down Expand Up @@ -191,7 +193,7 @@ export function formatPattern(pattern, params) {
);

if (paramValue != null)
pathname += paramValue;
pathname += encodeURIComponent(paramValue);
} else {
pathname += token;
}
Expand Down
4 changes: 2 additions & 2 deletions modules/__tests__/URLUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,13 @@ describe('formatPattern', function () {

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

describe('and a param has a forward slash', function () {
it('preserves the forward slash', function () {
expect(formatPattern(pattern, { id: 'the/id' })).toEqual('comments/the/id/edit');
expect(formatPattern(pattern, { id: 'the/id' })).toEqual('comments/the%2Fid/edit');
});
});

Expand Down

0 comments on commit 6baaa6c

Please sign in to comment.