diff --git a/pathname/build.js b/pathname/build.js index f5575fdc..463e1237 100644 --- a/pathname/build.js +++ b/pathname/build.js @@ -33,7 +33,7 @@ module.exports = function(template, params) { var newPathEnd = newQueryIndex < 0 ? newQueryEnd : newQueryIndex var result = resolved.slice(0, newPathEnd) - if (queryIndex >= 0) result += "?" + template.slice(queryIndex, queryEnd) + if (queryIndex >= 0) result += template.slice(queryIndex, queryEnd) if (newQueryIndex >= 0) result += (queryIndex < 0 ? "?" : "&") + resolved.slice(newQueryIndex, newQueryEnd) var querystring = buildQueryString(query) if (querystring) result += (queryIndex < 0 && newQueryIndex < 0 ? "?" : "&") + querystring diff --git a/pathname/tests/test-buildPathname.js b/pathname/tests/test-buildPathname.js index 1d6fc3f1..11d6cfb0 100644 --- a/pathname/tests/test-buildPathname.js +++ b/pathname/tests/test-buildPathname.js @@ -101,6 +101,21 @@ o.spec("buildPathname", function() { o(string).equals(prefix + "/image.png/view") }) + o("merges query strings", function() { + var string = buildPathname(prefix + "/item?a=1&b=2", {c: 3}) + + o(string).equals(prefix + "/item?a=1&b=2&c=3") + }) + o("merges query strings with other parameters", function() { + var string = buildPathname(prefix + "/item/:id?a=1&b=2", {id: "foo", c: 3}) + + o(string).equals(prefix + "/item/foo?a=1&b=2&c=3") + }) + o("consumes template parameters without modifying query string", function() { + var string = buildPathname(prefix + "/item/:id?a=1&b=2", {id: "foo"}) + + o(string).equals(prefix + "/item/foo?a=1&b=2") + }) } o.spec("absolute", function() { test("") }) o.spec("relative", function() { test("..") })