diff --git a/modules/PathUtils.js b/modules/PathUtils.js index c2b9a8a93..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) => - new RegExp("^" + prefix + "(\\/|\\?|#|$)", "i").test(path) + 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 diff --git a/modules/__tests__/HashHistory-test.js b/modules/__tests__/HashHistory-test.js index 70f30ee01..d51a1194c 100644 --- a/modules/__tests__/HashHistory-test.js +++ b/modules/__tests__/HashHistory-test.js @@ -269,5 +269,11 @@ describeHistory("a hash history", () => { 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') + }) }) })