-
Notifications
You must be signed in to change notification settings - Fork 197
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
Fix handling of urlencoded '+' #168
Conversation
rendered++; | ||
} | ||
}); | ||
|
||
FlowRouter.go(pathDef, {key: "abc"}); | ||
FlowRouter.go(pathDef, {key: "abc%20%2B%40%25"}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you need put encoded string here? I think that should be done by the router.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right that the router should encode it. See longer comment below.
I'm quite not sure about here. Need some voice from others as well. @elidoran @delgermurun |
What is the problem? What is exact behavior? |
pagejs appears to decode twice as @sprohaska describes. See pagejs line 491 and line 497. I don't know why they would decode it twice. The first time always happens and the second happens unless you disable it. The second one also explicitly changes pluses to spaces before decoding (here). I'm curious to know why they do that. Perhaps raise this issue with pagejs and see what they have to say? It seems like outright disabling it would alter behavior and possibly break backwards compatibility. How about providing a way for a user to specify FlowRouter should disable the extra decoding, and leave it enabled by default. Also, when I do the calls listed below I get an error:
Without the When I do So, this seems to require some review to determine what the behavior should actually be. |
I agree that a good solution may require clarification of the behavior in pagejs. I'm a bit unsure what I'd exactly expect from flow router. It seems reasonable that whatever I type in the browser's address field should be put into the params as urldecoded strings and I can just use them without any further decoding. I'm less sure what I'd expect from Any thoughts? |
Previously, '%2B' (aka '+') was incorrectly converted to space. Other urlencoded characters where affected, too. The reason was that pagejs's `Context()` calls `decodeURLEncodedURIComponent()` when initializing `pathname` and `Route.match()` calls `decodeURLEncodedURIComponent()` again on the matched `params` after splitting `pathname`. Since `decodeURLEncodedURIComponent()` replaces plus with space and the path is already decoded when calling it on the `params`, pluses were incorrectly converted to spaces; other urlencoded values were effected if the second urldecoding was not idempotent. pagejs's `Route.match()` calls `decodeURIComponent()` to decode `pathname` before applying the path regex, so there is no need to decode the entire path when initializing the `Context()`. pagejs's behavior seems odd at least; maybe it is a bug. This commit fixes the problem by disabling pagejs's `decodeURLEncodedURIComponent()` via the config object. There is no reasonable scenario in which the old behavior was correct and is modified by fixing the duplicate decoding. params are now correctly handled, and `FlowRouter` uses `qs.parse()` to handle query strings, which handles urldecoding, so pagejs should leave the query string alone. The semantic of `FlowRouter.path(pathDef, params, queryParams)` is clarified to urlencode `params` and `queryParams`, but not the `pathDef`. The tests are updated to exercise the encoding by using a few special characters.
2d5266c
to
4a792fd
Compare
I've updated the commit to implement the urlencoding in |
Note that encoding of params may be unintuitive for tail params as in I'm unsure whether this is acceptable. I'm not fully convinced, but also do not yet have a better proposal. |
I had to do add a few modifications to this. |
It looks correct and works, but it creates ugly URLs. I'm wondering whether flow router could provide an opt-in option to disable page.js URL encoding. It would preserve backward compatibility but also provide nicer URLs by avoiding the page.js weirdness. I haven't thought about it in more detail. Maybe I propose something when I find more time. |
Previously, '%2B' was incorrectly converted to space. The reason was
that page.js's
Context()
callsdecodeURLEncodedURIComponent()
wheninitializing
pathname
andRoute.match()
callsdecodeURLEncodedURIComponent()
again on the matchedparams
aftersplitting
pathname
. SincedecodeURLEncodedURIComponent()
replacesplus with space and the path is already decoded when calling it on the
params
, pluses were incorrectly converted to spaces.page's
Route.match()
callsdecodeURIComponent()
to decodepathname
before applying the path regex, so there is no need to decode the entire
path when initializing the
Context()
.page.js's behavior seems odd. But I haven't fully understood whether it
is a bug, so this fixes it by disabling page.js's
decodeURLEncodedURIComponent()
via the config object.The tests are updated to exercise the param matching with a few
urlencoded special characters.