Skip to content

Commit

Permalink
feat(routeToLocation): disable '//' situation in urls
Browse files Browse the repository at this point in the history
  • Loading branch information
woodcutter committed Nov 16, 2018
1 parent 391fd33 commit f507dcb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-unity-router",
"version": "1.5.0",
"version": "1.6.0",
"description": "Redux router that syncs history with store",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -42,7 +42,7 @@
"dependencies": {
"history": "^4.6.3",
"path": "^0.12.7",
"path-to-regexp": "^1.6.0",
"path-to-regexp": "^2.4.0",
"prop-types": "^15.5.10",
"query-string": "^4.3.4",
"url": "^0.11.0"
Expand Down
9 changes: 7 additions & 2 deletions src/parsers/routeToLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ const createMatchRouteToPath = registry => ({ id, params = {}, query = {}, hash
let pathname;

try {
// path-to-regexp (1.6.0): encodeURI by default, disable it with decodeURI
// remove front trailing backslash (disable '//' situation)
Object.keys(params).forEach(name => {
params[name] = (params[name] || '').replace(/^\//, '');
});

// path-to-regexp (2.4.0): encodeURI by default, disable it with encode option
// 'pretty' flag disable all encoding, besides '/', '?', '#'
pathname = decodeURIComponent(matcher(params));
pathname = matcher(params, { encode: value => value });
} catch (e) {
throw new RouterError(e.toString());
}
Expand Down

0 comments on commit f507dcb

Please sign in to comment.