From 7ed823801cf33c0579f22dfb86cb603ae50f53de Mon Sep 17 00:00:00 2001 From: Raees Iqbal Date: Mon, 6 Jul 2020 19:19:21 +0500 Subject: [PATCH] Functions: Handle query parameters correctly (#976) * Functions: Handle query parameters correctly * Add test for query parsing for functions requests * Formatting * paramsToObject: Preseve multiple values of same key * Simplify queryParams object creation * Express: Use 'simple' query parser --- src/utils/serve-functions.js | 1 + tests/dev.test.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/utils/serve-functions.js b/src/utils/serve-functions.js index e31963ea9d0..b2c2c8d26b6 100644 --- a/src/utils/serve-functions.js +++ b/src/utils/serve-functions.js @@ -293,6 +293,7 @@ function createFormSubmissionHandler(siteInfo) { async function serveFunctions(dir, siteInfo = {}) { const app = express() + app.set('query parser', 'simple') app.use( bodyParser.text({ diff --git a/tests/dev.test.js b/tests/dev.test.js index 054ef31992d..b197c0968a2 100644 --- a/tests/dev.test.js +++ b/tests/dev.test.js @@ -153,6 +153,12 @@ test('functions: not found', async t => { t.is(response.status, 404) }) +test('functions: query parameters parsing', async t => { + const response = await fetch(`http://${host}/api/echo?category[SOMETHING][]=something`).then(r => r.json()) + + t.deepEqual(response.queryStringParameters, { 'category[SOMETHING][]': 'something' }) +}) + test('Netlify Forms support', async t => { const form = new FormData() form.append('some', 'thing')