mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-01 16:44:16 +00:00
feat: enhance multipart-form file handling by filtering empty values in parser and stringifier (#8444)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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})`;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user