feat: enhance multipart-form file handling by filtering empty values in parser and stringifier (#8444)

This commit is contained in:
Sid
2026-07-01 13:21:49 +05:30
committed by GitHub
parent 4ab68fc71f
commit ed468dba88
4 changed files with 94 additions and 2 deletions

View File

@@ -266,7 +266,7 @@ const mapPairListToKeyValPairsMultipart = (pairList = [], parseEnabled = true) =
if (pair.value.startsWith('@file(') && pair.value.endsWith(')')) {
let filestr = pair.value.replace(/^@file\(/, '').replace(/\)$/, '');
pair.type = 'file';
pair.value = filestr.split('|');
pair.value = filestr.split('|').filter(Boolean);
}
return pair;

View File

@@ -560,7 +560,7 @@ ${indentString(body.sparql)}
}
if (item.type === 'file') {
const filepaths = Array.isArray(item.value) ? item.value : [];
const filepaths = (Array.isArray(item.value) ? item.value : []).filter(Boolean);
const filestr = filepaths.join('|');
const value = `@file(${filestr})`;

View File

@@ -485,5 +485,55 @@ body:multipart-form {
const output = parser(input);
expect(output).toEqual(expected);
});
it('parses an empty multipart-form file value as an empty array', () => {
const input = `
body:multipart-form {
file: @file()
}
`;
const expected = {
body: {
multipartForm: [
{
name: 'file',
value: [],
enabled: true,
type: 'file',
contentType: ''
}
]
}
};
const output = parser(input);
expect(output).toEqual(expected);
});
it('drops empty entries when parsing multiple multipart-form file paths', () => {
const input = `
body:multipart-form {
file: @file(a.txt||b.txt)
}
`;
const expected = {
body: {
multipartForm: [
{
name: 'file',
value: ['a.txt', 'b.txt'],
enabled: true,
type: 'file',
contentType: ''
}
]
}
};
const output = parser(input);
expect(output).toEqual(expected);
});
});
});

View File

@@ -54,6 +54,48 @@ describe('jsonToBru stringify', () => {
});
});
describe('body:multipart-form file values', () => {
it('stringifies an empty file value without a leading pipe', () => {
const input = {
body: {
multipartForm: [
{
name: 'file',
value: [],
enabled: true,
type: 'file',
contentType: ''
}
]
}
};
const output = stringify(input);
expect(output).toContain('file: @file()');
expect(output).not.toContain('@file(|');
});
it('drops empty entries when stringifying multiple file paths', () => {
const input = {
body: {
multipartForm: [
{
name: 'file',
value: ['', '/path/to/file.csv'],
enabled: true,
type: 'file',
contentType: ''
}
]
}
};
const output = stringify(input);
expect(output).toContain('file: @file(/path/to/file.csv)');
expect(output).not.toContain('@file(|');
});
});
describe('multi-line values', () => {
it('handles multi-line values in URL, headers, params, and vars', () => {
const input = {