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

When query value starts with #, router doesn't recognize it #804

Closed
gaearon opened this issue Feb 9, 2015 · 5 comments · Fixed by #805
Closed

When query value starts with #, router doesn't recognize it #804

gaearon opened this issue Feb 9, 2015 · 5 comments · Fixed by #805

Comments

@gaearon
Copy link
Contributor

gaearon commented Feb 9, 2015

I'm doing this.replaceWith('search', {}, { q: '#test2' }). In this case q is just a string user types into an input field. It's a search field, and user may want to find something by a hashtag.

In this case router will simply ignore this query parameter as if it never was there. I'd expect it to be encoded and correctly returned in state.query later.

qs.stringify encodes it, but decodeURIComponent decodes it back and so it is passed verbatim to the location that assumes it's a hash.

Should we just manually encode # in a query? cc @mjackson who knows that logic

@gaearon
Copy link
Contributor Author

gaearon commented Feb 9, 2015

In fact it seems that replacing decodeURIComponent with decodeURI on this line solves the issue.

This also fixed subtle breakage caused by entering something like &q=lalala in search field (which causes state.query.q to become an array).

@gaearon
Copy link
Contributor Author

gaearon commented Feb 9, 2015

Another failing case: if I call replaceWith with a+b in one of the query parameters, it will come back as a b to me.

@gaearon
Copy link
Contributor Author

gaearon commented Feb 9, 2015

My proposed fix is #805 along with previously failing tests.
Does this make sense?

@gaearon
Copy link
Contributor Author

gaearon commented Feb 10, 2015

Actually all I did to get it working was removing decodeURIComponent call: 42ddc23d5671403d48ed64e4dd85460af3105a5c.

When @mjackson is back, I hope he can shine some light on why he added it.

gaearon added a commit to gaearon/react-router that referenced this issue Feb 11, 2015
Previously, special characters in query were left as is, potentially overwriting other query parameters and causing ambiguity.
Now, they are properly escaped.

Fixes remix-run#804.
@mjackson
Copy link
Member

@gaearon I'm looking at this right now. Time to get rid of this bug :)

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

Successfully merging a pull request may close this issue.

2 participants