From 41bd525c9209661a7ef4ea37037d35e727d595d1 Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Thu, 18 Jun 2015 23:17:56 -0700 Subject: [PATCH] [fixed] Properly escape splats --- modules/DOMUtils.js | 11 ++++------- modules/URLUtils.js | 8 ++++---- modules/__tests__/URLUtils-test.js | 2 +- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/modules/DOMUtils.js b/modules/DOMUtils.js index 8bebfcbc41..58f4963b5c 100644 --- a/modules/DOMUtils.js +++ b/modules/DOMUtils.js @@ -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) { diff --git a/modules/URLUtils.js b/modules/URLUtils.js index 6b8224067c..d73ca2c808 100644 --- a/modules/URLUtils.js +++ b/modules/URLUtils.js @@ -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(); @@ -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 === ')') { diff --git a/modules/__tests__/URLUtils-test.js b/modules/__tests__/URLUtils-test.js index fad5002d3f..5eccb53b1b 100644 --- a/modules/__tests__/URLUtils-test.js +++ b/modules/__tests__/URLUtils-test.js @@ -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'); }); });