diff --git a/Gruntfile.js b/Gruntfile.js index 18aaf603..bbdf6c9c 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -150,6 +150,7 @@ module.exports = function(grunt) { comparisons: {expand: true, cwd: inputFolder + "/layout/comparisons/", src: "./**", dest: currentVersionArchiveFolder + "/comparisons/"}, unminified: {src: "mithril.js", dest: currentVersionArchiveFolder + "/mithril.js"}, minified: {src: "mithril.min.js", dest: currentVersionArchiveFolder + "/mithril.min.js"}, + readme: {src: "README.md", dest: currentVersionArchiveFolder + "/README.md"}, map: {src: "mithril.min.js.map", dest: currentVersionArchiveFolder + "/mithril.min.js.map"}, typescript: {src: "mithril.d.ts", dest: currentVersionArchiveFolder + "/mithril.d.ts"}, publish: {expand: true, cwd: currentVersionArchiveFolder, src: "./**", dest: outputFolder}, diff --git a/docs/change-log.md b/docs/change-log.md index 3ad284ed..6424e92f 100644 --- a/docs/change-log.md +++ b/docs/change-log.md @@ -9,6 +9,7 @@ ### Bug Fixes: - prevent empty class attributes [#382](https://github.com/lhorie/mithril.js/issues/382) +- array-to-querystring serialization in `m.request` now behaves like jQuery [#426](https://github.com/lhorie/mithril.js/issues/426) --- diff --git a/docs/layout/package.json b/docs/layout/package.json index 9ac09614..5f150139 100644 --- a/docs/layout/package.json +++ b/docs/layout/package.json @@ -7,5 +7,5 @@ "repository": {"type": "git", "url": "https://github.com/lhorie/mithril"}, "main": "mithril.js", "licenses": [{"type": "MIT", "url": "http://opensource.org/licenses/MIT"}], - "files": ["mithril.min.js", "mithril.min.map", "mithril.js"] -} \ No newline at end of file + "files": ["mithril.min.js", "mithril.min.map", "mithril.js", "README.*"] +} diff --git a/mithril.js b/mithril.js index bd56e1d3..9685f42c 100644 --- a/mithril.js +++ b/mithril.js @@ -705,10 +705,17 @@ var m = (function app(window, undefined) { var str = []; for(var prop in object) { var key = prefix ? prefix + "[" + prop + "]" : prop, value = object[prop]; - str.push(value != null && type.call(value) === OBJECT ? buildQueryString(value, key) : encodeURIComponent(key) + "=" + encodeURIComponent(value)) + var valueType = type.call(value) + var pair = value != null && (valueType === OBJECT) ? + buildQueryString(value, key) : + valueType === ARRAY ? + value.map(function(item) {return encodeURIComponent(key) + "=" + encodeURIComponent(item)}).join("&") : + encodeURIComponent(key) + "=" + encodeURIComponent(value) + str.push(pair) } return str.join("&") } + function parseQueryString(str) { var pairs = str.split("&"), params = {}; for (var i = 0, len = pairs.length; i < len; i++) { diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index 9fa41460..cbf52d4d 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -1781,6 +1781,11 @@ function testMithril(mock) { mock.XMLHttpRequest.$instances.pop().onreadystatechange() return prop().url === "test" }) + test(function() { + var prop = m.request({method: "GET", url: "test", data: {foo: [1, 2]}}) + mock.XMLHttpRequest.$instances.pop().onreadystatechange() + return prop().url === "test?foo=1&foo=2" + }) // m.request over jsonp test(function(){