Skip to content

Commit

Permalink
[fixed] Properly escape splats
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Jun 19, 2015
1 parent 6baaa6c commit 41bd525
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
11 changes: 4 additions & 7 deletions modules/DOMUtils.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
export var canUseDOM = !!(
(typeof window !== 'undefined' &&
window.document && window.document.createElement)
typeof window !== 'undefined' && window.document && window.document.createElement
);

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

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

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

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

if (paramValue != null)
pathname += paramValue;
pathname += encodeURIComponent(paramValue);
} else if (token === '(') {
parenCount += 1;
} else if (token === ')') {
Expand Down
2 changes: 1 addition & 1 deletion modules/__tests__/URLUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe('formatPattern', function () {

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

Expand Down

0 comments on commit 41bd525

Please sign in to comment.