From c3d3fa7315dc0f80785978a6a702955e17fe4a9e Mon Sep 17 00:00:00 2001 From: Richard Eames Date: Thu, 18 Sep 2014 10:57:30 -0600 Subject: [PATCH] Check that the 2nd argument to m.route is a string --- mithril.js | 2 +- tests/mithril-tests.js | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/mithril.js b/mithril.js index 47870d97..a85b490a 100644 --- a/mithril.js +++ b/mithril.js @@ -517,7 +517,7 @@ Mithril = m = new function app(window, undefined) { var redirect = function() {}, routeParams = {}, currentRoute m.route = function() { if (arguments.length === 0) return currentRoute - else if (arguments.length === 3 && typeof arguments[1] == "string") { + else if (arguments.length === 3 && isStr(arguments[1])) { var root = arguments[0], defaultRoute = arguments[1], router = arguments[2] redirect = function(source) { var path = currentRoute = normalizeRoute(source) diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 9efe378c..6d293b74 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1525,6 +1525,38 @@ function testMithril(mock) { mock.requestAnimationFrame.$resolve() //teardown return mock.location.search == "?/test23/" && root.childNodes[0].nodeValue === "bar" }) + test(function() { + mock.requestAnimationFrame.$resolve() //setup + mock.location.search = "?" + + var root = mock.document.createElement("div") + var value + m.route(root, String("/foo+bar"), { + "/:arg": { + controller: function() {value = m.route.param("arg")}, + view: function(ctrl) { + return "" + } + } + }) + return value == "foo+bar" + }) + test(function() { + mock.requestAnimationFrame.$resolve() //setup + mock.location.search = "?" + + var root = mock.document.createElement("div") + var value + m.route(root, new String("/foo+bar"), { + "/:arg": { + controller: function() {value = m.route.param("arg")}, + view: function(ctrl) { + return "" + } + } + }) + return value == "foo+bar" + }) //end m.route //m.prop