Skip to content

Commit

Permalink
Merge pull request #62 from davidpett/handle-malformed-uri
Browse files Browse the repository at this point in the history
handle malformed URI error
  • Loading branch information
mmun committed Oct 25, 2015
2 parents 379d612 + ed41239 commit 2a5a26c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion lib/route-recognizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ function addSegment(currentState, segment) {
function decodeQueryParamPart(part) {
// http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
part = part.replace(/\+/gm, '%20');
return decodeURIComponent(part);
var result;
try {
result = decodeURIComponent(part);
} catch(error) {result = '';}
return result;
}

// The main interface
Expand Down
9 changes: 9 additions & 0 deletions tests/recognizer-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ test("Multiple routes recognize", function() {
resultsMatch(router.recognize("/bar/1"), [{ handler: handler2, params: { baz: "1" }, isDynamic: true }]);
});

test("ignore the URI malformed error", function() {
var handler1 = { handler: 1 };
var router = new RouteRecognizer();

router.add([{ path: "/foo", handler: handler1 }]);

deepEqual(router.recognize("/foo?a=1%").queryParams, {a: ""});
});

test("Multiple routes with overlapping query params recognize", function() {
var handler1 = { handler: 1 };
var handler2 = { handler: 2 };
Expand Down
5 changes: 2 additions & 3 deletions tests/router-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ test("supports star routes", function() {

test("star route does not swallow trailing `/`", function() {
var r;

router.map(function(match) {
match("/").to("posts");
match("/*everything").to("glob");
Expand All @@ -173,7 +173,7 @@ test("support star route before other segment", function() {
});

["folder1/folder2/folder3//the-extra-stuff/", "folder1/folder2/folder3//the-extra-stuff"].forEach(function(r) {
matchesRoute("/" + r, [{ handler: "glob", params: {everything: "folder1/folder2/folder3/", extra: "the-extra-stuff"}, isDynamic: true}]);
matchesRoute("/" + r, [{ handler: "glob", params: {everything: "folder1/folder2/folder3/", extra: "the-extra-stuff"}, isDynamic: true}]);
});
});

Expand Down Expand Up @@ -258,4 +258,3 @@ test("supports add-route callback", function() {
matchesRoute("/posts/new", [{ handler: "newPost", params: {}, isDynamic: false }]);
ok(called, "The add-route callback was called.");
});

0 comments on commit 2a5a26c

Please sign in to comment.