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

Decode route before parsing. #70

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/route-recognizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ EpsilonSegment.prototype = {
function parse(route, names, specificity) {
// normalize route as not starting with a "/". Recognition will
// also normalize.
route = decodeURIComponent(route);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would decode special URI characters before parsing, so an encoded slash would get parsed as a path separator, decodeURIComponent should not happen before parsing, decodeURI is for normalizing a URI so that all the optionally encoded characters are decoded.


if (route.charAt(0) === "/") { route = route.substr(1); }

var segments = route.split("/"), results = [];
Expand Down
8 changes: 8 additions & 0 deletions tests/router-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ test("support star route before other segment", function() {
});
});

test("supports URL encoded route's calls to match", function() {
router.map(function(match) {
match("/all%20posts").to("indexPost");
});

matchesRoute("/all%20posts", [{ handler: "indexPost", params: {}, isDynamic: false }]);
});

test("support nested star route", function() {
router.map(function(match) {
match("/*everything").to("glob", function(match){
Expand Down