From 98fdf5d4d93e6cc3eee7c58a97b93170167c0381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20W=C3=BCthrich?= Date: Tue, 24 Apr 2018 12:27:15 +0200 Subject: [PATCH] Add support for nested objects in params --- package-lock.json | 11 +++++++++-- package.json | 1 + src/index.js | 2 +- test/integration/index.spec.js | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index bc42713f..5d40589a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3100,6 +3100,7 @@ "dev": true, "optional": true, "requires": { + "nan": "2.10.0", "node-pre-gyp": "0.6.39" }, "dependencies": { @@ -6682,6 +6683,13 @@ "integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s=", "dev": true }, + "nan": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.10.0.tgz", + "integrity": "sha512-bAdJv7fBLhWC+/Bls0Oza+mvTaNQtP+1RyhhhvD95pgUJz6XM5IzgmxOkItJ9tkoCiplvAnXI1tNmmUD/eScyA==", + "dev": true, + "optional": true + }, "nanomatch": { "version": "1.2.9", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.9.tgz", @@ -8198,8 +8206,7 @@ "qs": { "version": "6.5.1", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", - "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==", - "dev": true + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" }, "querystring": { "version": "0.2.0", diff --git a/package.json b/package.json index 3879b940..e29a60ba 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "lodash": "4.17.5", "nanomatch": "1.2.9", "path-to-regexp": "1.7.0", + "qs": "6.5.1", "serve-static": "1.13.2" }, "engines": { diff --git a/src/index.js b/src/index.js index 3d8ca5e2..3f98b4f6 100644 --- a/src/index.js +++ b/src/index.js @@ -8,7 +8,7 @@ const http = require("http"); const https = require("https"); -const queryString = require("querystring"); +const queryString = require("qs"); const deprecate = require("depd")("moleculer-web"); const _ = require("lodash"); diff --git a/test/integration/index.spec.js b/test/integration/index.spec.js index 18a92ce1..6400280f 100644 --- a/test/integration/index.spec.js +++ b/test/integration/index.spec.js @@ -789,6 +789,32 @@ describe("Test aliases", () => { }); }); + it("GET opt-test with array params", () => { + return request(server) + .get("/api/opt-test") + .query("a=1&a=2") + .expect(200) + .expect("Content-Type", "application/json; charset=utf-8") + .then(res => { + expect(res.body.params).toEqual({ + a: ["1", "2"], + }); + }); + }); + + it("GET opt-test with nested params", () => { + return request(server) + .get("/api/opt-test") + .query("foo[bar]=a&foo[bar]=b&foo[baz]=c") + .expect(200) + .expect("Content-Type", "application/json; charset=utf-8") + .then(res => { + expect(res.body.params).toEqual({ + foo: { bar: ["a", "b"], baz: "c" } + }); + }); + }); + it("GET opt-test/:name? without name", () => { return request(server) .get("/api/opt-test")