Skip to content

Commit

Permalink
bugfix to basename
Browse files Browse the repository at this point in the history
  • Loading branch information
Mate Hegedus committed Nov 21, 2017
1 parent dca21ea commit 3c138f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/PathUtils.js
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions modules/__tests__/HashHistory-test.js
Expand Up @@ -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')
})
})
})

0 comments on commit 3c138f8

Please sign in to comment.