diff --git a/modules/PathUtils.js b/modules/PathUtils.js index ffa394daa..e5abec7d2 100644 --- a/modules/PathUtils.js +++ b/modules/PathUtils.js @@ -7,7 +7,10 @@ export function stripLeadingSlash(path) { } export function hasBasename(path, prefix) { - return new RegExp('^' + prefix + '(\\/|\\?|#|$)', 'i').test(path); + return ( + path.toLowerCase().indexOf(prefix.toLowerCase()) === 0 && + '/?#'.indexOf(path.charAt(prefix.length)) !== -1 + ); } export function stripBasename(path, prefix) { diff --git a/modules/__tests__/HashHistory-test.js b/modules/__tests__/HashHistory-test.js index 725fd766f..07f491c29 100644 --- a/modules/__tests__/HashHistory-test.js +++ b/modules/__tests__/HashHistory-test.js @@ -161,9 +161,7 @@ describe('a hash history', () => { let history; beforeEach(() => { - history = createHistory({ - getUserConfirmation - }); + history = createHistory({ getUserConfirmation }); }); it('receives the next location and action as arguments', done => { @@ -184,9 +182,7 @@ describe('a hash history', () => { describe('"hashbang" hash path coding', () => { let history; beforeEach(() => { - history = createHistory({ - hashType: 'hashbang' - }); + history = createHistory({ hashType: 'hashbang' }); }); it('properly encodes and decodes window.location.hash', done => { @@ -197,9 +193,7 @@ describe('a hash history', () => { describe('"noslash" hash path coding', () => { let history; beforeEach(() => { - history = createHistory({ - hashType: 'noslash' - }); + history = createHistory({ hashType: 'noslash' }); }); it('properly encodes and decodes window.location.hash', done => { @@ -210,9 +204,7 @@ describe('a hash history', () => { describe('"slash" hash path coding', () => { let history; beforeEach(() => { - history = createHistory({ - hashType: 'slash' - }); + history = createHistory({ hashType: 'slash' }); }); it('properly encodes and decodes window.location.hash', done => { @@ -256,5 +248,11 @@ describe('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'); + }); }); });