diff --git a/packages/plugin-adapter-netlify/src/index.js b/packages/plugin-adapter-netlify/src/index.js index 7336f174f..992304c47 100644 --- a/packages/plugin-adapter-netlify/src/index.js +++ b/packages/plugin-adapter-netlify/src/index.js @@ -18,10 +18,12 @@ function generateOutputFormat(id) { if (['GET', 'HEAD'].includes(httpMethod.toUpperCase())) { format = null } else if (contentType.includes('application/x-www-form-urlencoded')) { + const searchParams = new URLSearchParams(body); const formData = new FormData(); - for (const key of Object.keys(body)) { - formData.append(key, body[key]); + for (const key of searchParams.keys()) { + const value = searchParams.get(key); + formData.append(key, value); } // when using FormData, let Request set the correct headers diff --git a/packages/plugin-adapter-netlify/test/cases/build.default/build.default.spec.js b/packages/plugin-adapter-netlify/test/cases/build.default/build.default.spec.js index a51f5c69f..e93209128 100644 --- a/packages/plugin-adapter-netlify/test/cases/build.default/build.default.spec.js +++ b/packages/plugin-adapter-netlify/test/cases/build.default/build.default.spec.js @@ -215,7 +215,7 @@ describe('Build Greenwood With: ', function() { const { handler } = await import(new URL(`./${name}/${name}.js`, netlifyFunctionsOutputUrl)); const response = await handler({ rawUrl: 'http://localhost:8080/api/submit-form-data', - body: { name: param }, + body: `name=${param}`, httpMethod: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded'