Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ? character in basename for browser history. #566

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
@@ -1,3 +1,9 @@
## HEAD

- Allow ? character to be used in basename for browser history (see [#564])

[#564]: https://github.com/ReactTraining/history/issues/564

## [v4.6.3]
> Jun 20, 2017

Expand Down
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);
new RegExp("^" + prefix.replace("?", "\\?") + "(\\/|\\?|#|$)", "i").test(path);

export const stripBasename = (path, prefix) =>
hasBasename(path, prefix) ? path.substr(prefix.length) : path;
Expand Down
6 changes: 6 additions & 0 deletions modules/__tests__/BrowserHistory-test.js
Expand Up @@ -230,5 +230,11 @@ describeHistory("a browser history", () => {
const history = createHistory({ basename: "/prefix" });
expect(history.location.pathname).toEqual("/");
});

it("handles ? character in basename correctly", () => {
window.history.replaceState(null, null, "/prefix?rest/pathname");
const history = createHistory({ basename: "/prefix?rest" });
expect(history.location.pathname).toEqual("/pathname");
});
});
});