Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clarify and fix handling of urlencoding
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.
- Loading branch information