diff --git a/packages/bruno-lang/v2/src/bruToJson.js b/packages/bruno-lang/v2/src/bruToJson.js index f62ad9737..19f86597b 100644 --- a/packages/bruno-lang/v2/src/bruToJson.js +++ b/packages/bruno-lang/v2/src/bruToJson.js @@ -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; diff --git a/packages/bruno-lang/v2/src/jsonToBru.js b/packages/bruno-lang/v2/src/jsonToBru.js index 654c02f34..a30b1fb4a 100644 --- a/packages/bruno-lang/v2/src/jsonToBru.js +++ b/packages/bruno-lang/v2/src/jsonToBru.js @@ -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})`; diff --git a/packages/bruno-lang/v2/tests/bruToJson.spec.js b/packages/bruno-lang/v2/tests/bruToJson.spec.js index 261d626c6..e623edf0f 100644 --- a/packages/bruno-lang/v2/tests/bruToJson.spec.js +++ b/packages/bruno-lang/v2/tests/bruToJson.spec.js @@ -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); + }); }); }); diff --git a/packages/bruno-lang/v2/tests/jsonToBru.spec.js b/packages/bruno-lang/v2/tests/jsonToBru.spec.js index 78d79592a..40720f4a0 100644 --- a/packages/bruno-lang/v2/tests/jsonToBru.spec.js +++ b/packages/bruno-lang/v2/tests/jsonToBru.spec.js @@ -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 = {