From a80621e3a61b84e172a5b6fcd4eb1b4b2b5b2d15 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Wed, 7 May 2014 23:09:27 -0400 Subject: [PATCH] fix url decoding in route args --- mithril.js | 2 +- tests/mithril-tests.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 4eafa038..47a0d7a1 100644 --- a/mithril.js +++ b/mithril.js @@ -312,7 +312,7 @@ Mithril = m = new function app(window) { return !void path.replace(matcher, function() { var keys = route.match(/:[^\/]+/g) var values = [].slice.call(arguments, 1, -2) - for (var i = 0; i < keys.length; i++) routeParams[keys[i].replace(/:|\./g, "")] = values[i] + for (var i = 0; i < keys.length; i++) routeParams[keys[i].replace(/:|\./g, "")] = decodeURIComponent(values[i]) m.module(root, router[route]) }) } diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index d358b22c..9f323085 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -523,6 +523,24 @@ function testMithril(mock) { mock.performance.$elapse(50) //teardown return mock.location.search == "?/test9/foo/bar/SEP/baz" && root.childNodes[0].nodeValue === "foo/bar_baz" }) + test(function() { + mock.performance.$elapse(50) //setup + mock.location.search = "?" + + var root = mock.document.createElement("div") + m.route.mode = "search" + m.route(root, "/test10/foo%20bar", { + "/test10/:test": { + controller: function() {}, + view: function() { + return m.route.param("test") + } + } + }) + mock.performance.$elapse(50) //teardown + return root.childNodes[0].nodeValue === "foo bar" + }) + //end m.route //m.prop test(function() {