Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug/issue 1048 handle URL encoded Netlify form params #1148

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/plugin-adapter-netlify/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading