diff --git a/mithril.js b/mithril.js index 1f9aac4e..47870d97 100644 --- a/mithril.js +++ b/mithril.js @@ -1,9 +1,10 @@ Mithril = m = new function app(window, undefined) { - var sObj = "[object Object]", sArr = "[object Array]"; + var sObj = "[object Object]", sArr = "[object Array]", sStr = "[object String]" function type(obj) {return {}.toString.call(obj)} function isObj(obj) {return type(obj) == sObj} function isArr(obj) {return type(obj) == sArr} function isFn(obj) {return typeof obj == "function"} + function isStr(obj){ return type(obj) == sStr} var parser = /(?:(^|#|\.)([^#\.\[\]]+))|(\[.+?\])/g, attrParser = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/ var voidElements = /AREA|BASE|BR|COL|COMMAND|EMBED|HR|IMG|INPUT|KEYGEN|LINK|META|PARAM|SOURCE|TR‌​ACK|WBR/ @@ -544,7 +545,7 @@ Mithril = m = new function app(window, undefined) { element.addEventListener("click", routeUnobtrusive) } } - else if (typeof arguments[0] == "string") { + else if (isStr(arguments[0])) { currentRoute = arguments[0] var querystring = isObj(arguments[1]) ? buildQueryString(arguments[1]) : null if (querystring) currentRoute += (currentRoute.indexOf("?") === -1 ? "?" : "&") + querystring diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index a6e9b42e..9efe378c 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1495,6 +1495,36 @@ function testMithril(mock) { }) return value == "foo+bar" }) + test(function() { + mock.requestAnimationFrame.$resolve() //setup + mock.location.search = "?" + + var root = mock.document.createElement("div") + m.route.mode = "search" + m.route(root, "/", { + "/": {controller: function() {}, view: function() {return "foo"}}, + "/test22": {controller: function() {}, view: function() {return "bar"}} + }) + mock.requestAnimationFrame.$resolve() + m.route(String("/test22/")) + mock.requestAnimationFrame.$resolve() //teardown + return mock.location.search == "?/test22/" && root.childNodes[0].nodeValue === "bar" + }) + test(function() { + mock.requestAnimationFrame.$resolve() //setup + mock.location.search = "?" + + var root = mock.document.createElement("div") + m.route.mode = "search" + m.route(root, "/", { + "/": {controller: function() {}, view: function() {return "foo"}}, + "/test23": {controller: function() {}, view: function() {return "bar"}} + }) + mock.requestAnimationFrame.$resolve() + m.route(new String("/test23/")) + mock.requestAnimationFrame.$resolve() //teardown + return mock.location.search == "?/test23/" && root.childNodes[0].nodeValue === "bar" + }) //end m.route //m.prop