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

basename is used in a RegExp without escaping. #512

Closed
Parakleta opened this issue Aug 14, 2017 · 3 comments
Closed

basename is used in a RegExp without escaping. #512

Parakleta opened this issue Aug 14, 2017 · 3 comments

Comments

@Parakleta
Copy link

I really want to use the query string method (i.e. <BrowserRouter basename="?"> described in #435 (comment)) since this gives me browser history without having to add a catch-all rule in the server, but unfortunately the hasBasename function treats the basename as part of a regular expression which causes some problems.

https://github.com/ReactTraining/history/blob/8d98aec1366b86e3832dbfd7dcc480d1f9a5275c/modules/PathUtils.js#L7-L8

This problem is larger than just my use of it because [.*+()] are all legal URI path characters and have special meaning in regular expressions. The relevant code should probably check that the path startsWith the prefix and that the character following the prefix is one of the intended, something like:

path === prefix || path.startsWith(prefix) && "/?#".indexOf(path.charAt(prefix.length)) !== -1

This doesn't deal with the case-insensitivity of percent encoded URIs but then the existing code treats paths as entirely case-insensitive when it shouldn't. I'm not sure if any special handling is required (or desired) for percent encoding.

@mjackson
Copy link
Member

The only basename we support for now are URL pathnames. What's your use case for wanting to put the path in the query string?

@Parakleta
Copy link
Author

Parakleta commented Nov 20, 2017

Actually as I already explained in the second paragraph you don’t support all URL path names for basename because you don’t support the characters [.*+()] which are all legal URL path name characters.

I’m not sure how my use case is relevant beyond providing context but it is exactly as I described in the opening paragraph of my bug report. I want browser history without having to modify the server; using the query string seems to be the obvious way to get the best of both worlds. Also, the linked issue #435 has further discussion.

@mjackson
Copy link
Member

This is being addressed in #544. Let's follow up there.

@lock lock bot locked as resolved and limited conversation to collaborators Jun 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants