fix(Webhook Node): Backward compatible form-data parsing for non-array fields (#6967)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2023-08-18 12:34:42 +02:00 committed by GitHub
parent 41db6371f0
commit 9455bcfef5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 5 deletions

View file

@ -309,6 +309,11 @@ export async function executeWebhook(
});
req.body = await new Promise((resolve) => {
form.parse(req, async (err, data, files) => {
for (const key in data) {
if (Array.isArray(data[key]) && data[key].length === 1) {
data[key] = data[key][0];
}
}
resolve({ data, files });
});
});

View file

@ -113,7 +113,9 @@ describe('Webhook API', () => {
test('should handle multipart/form-data', async () => {
const response = await agent
.post('/webhook/abcd')
.field('field', 'value')
.field('field1', 'value1')
.field('field2', 'value2')
.field('field2', 'value3')
.attach('file', Buffer.from('random-text'))
.set('content-type', 'multipart/form-data');
@ -125,7 +127,7 @@ describe('Webhook API', () => {
file: [file],
},
} = response.body.body;
expect(data).toEqual({ field: ['value'] });
expect(data).toEqual({ field1: 'value1', field2: ['value2', 'value3'] });
expect(file.mimetype).toEqual('application/octet-stream');
expect(readFileSync(file.filepath, 'utf-8')).toEqual('random-text');
});

View file

@ -127,7 +127,7 @@ export class Webhook extends Node {
const response: INodeExecutionData = {
json: {
headers: req.headers,
params: req.params,
params: {},
query: req.query,
body: req.body,
},
@ -207,7 +207,7 @@ export class Webhook extends Node {
binary: {},
json: {
headers: req.headers,
params: req.params,
params: {},
query: req.query,
body: data,
},
@ -263,7 +263,7 @@ export class Webhook extends Node {
binary: {},
json: {
headers: req.headers,
params: req.params,
params: {},
query: req.query,
body: {},
},