From 3c138f897f33357b6deb569098ecabafdef35b05 Mon Sep 17 00:00:00 2001 From: Mate Hegedus Date: Tue, 21 Nov 2017 11:33:51 +0000 Subject: [PATCH 1/3] bugfix to basename --- modules/PathUtils.js | 2 +- modules/__tests__/HashHistory-test.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/PathUtils.js b/modules/PathUtils.js index c2b9a8a93..2a55e9a80 100644 --- a/modules/PathUtils.js +++ b/modules/PathUtils.js @@ -5,7 +5,7 @@ export const stripLeadingSlash = path => path.charAt(0) === "/" ? path.substr(1) : path export const hasBasename = (path, prefix) => - new RegExp("^" + prefix + "(\\/|\\?|#|$)", "i").test(path) + path.toLowerCase().lastIndexOf(prefix.toLowerCase(), 0) === 0 && "/?#".indexOf(path.charAt(prefix.length)) !== -1 export const stripBasename = (path, prefix) => hasBasename(path, prefix) ? path.substr(prefix.length) : path diff --git a/modules/__tests__/HashHistory-test.js b/modules/__tests__/HashHistory-test.js index 70f30ee01..bfd91dc80 100644 --- a/modules/__tests__/HashHistory-test.js +++ b/modules/__tests__/HashHistory-test.js @@ -268,6 +268,12 @@ describeHistory("a hash history", () => { window.location.hash = "#/prefix#rest" const history = createHistory({ basename: "/prefix" }) expect(history.location.pathname).toEqual("/") + }) + + it('allows URL with regex special characters', () => { + window.location.hash = '/prefix$special/hello' + const history = createHistory({ basename: '/prefix$special'}) + expect(history.location.pathname).toEqual('/hello') }) }) }) From 2ee6521930fae0e604bd41f552066ba6d5d4d66d Mon Sep 17 00:00:00 2001 From: Mate Hegedus Date: Tue, 21 Nov 2017 11:47:15 +0000 Subject: [PATCH 2/3] Formatting --- modules/__tests__/HashHistory-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/__tests__/HashHistory-test.js b/modules/__tests__/HashHistory-test.js index bfd91dc80..d51a1194c 100644 --- a/modules/__tests__/HashHistory-test.js +++ b/modules/__tests__/HashHistory-test.js @@ -270,7 +270,7 @@ describeHistory("a hash history", () => { expect(history.location.pathname).toEqual("/") }) - it('allows URL with regex special characters', () => { + it('allows URL with regex special characters', () => { window.location.hash = '/prefix$special/hello' const history = createHistory({ basename: '/prefix$special'}) expect(history.location.pathname).toEqual('/hello') From fe048f8b465596dc0042ba2f13e6c483e4b4f6f5 Mon Sep 17 00:00:00 2001 From: Mate Hegedus Date: Wed, 22 Nov 2017 09:37:44 +0000 Subject: [PATCH 3/3] using indexOf instead of lastIndexOf --- modules/PathUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/PathUtils.js b/modules/PathUtils.js index 2a55e9a80..b02461932 100644 --- a/modules/PathUtils.js +++ b/modules/PathUtils.js @@ -5,7 +5,7 @@ export const stripLeadingSlash = path => path.charAt(0) === "/" ? path.substr(1) : path export const hasBasename = (path, prefix) => - path.toLowerCase().lastIndexOf(prefix.toLowerCase(), 0) === 0 && "/?#".indexOf(path.charAt(prefix.length)) !== -1 + path.toLowerCase().indexOf(prefix.toLowerCase()) === 0 && "/?#".indexOf(path.charAt(prefix.length)) !== -1 export const stripBasename = (path, prefix) => hasBasename(path, prefix) ? path.substr(prefix.length) : path