diff --git a/packages/bruno-lang/src/body-tag.js b/packages/bruno-lang/src/body-tag.js index 1ad390b55..22824b5cd 100644 --- a/packages/bruno-lang/src/body-tag.js +++ b/packages/bruno-lang/src/body-tag.js @@ -26,9 +26,6 @@ const bodyTextBegin = regex(/^body\s*\(\s*type\s*=\s*text\s*\)\s*\r?\n/); // body(type=xml) const bodyXmlBegin = regex(/^body\s*\(\s*type\s*=\s*xml\s*\)\s*\r?\n/); -// body(type=form-url-encoded) -const bodyFormUrlEncoded = regex(/^body\s*\(\s*type\s*=\s*form-url-encoded\s*\)\s*\r?\n/); - const bodyEnd = regex(/^[\r?\n]+\/body\s*[\r?\n]*/); const bodyJsonTag = between(bodyJsonBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyJson) => { @@ -108,6 +105,12 @@ const line = sequenceOf([ const lines = many(line); const keyvalLines = sepBy(newline)(lines); +// body(type=form-url-encoded) +const bodyFormUrlEncoded = regex(/^body\s*\(\s*type\s*=\s*form-url-encoded\s*\)\s*\r?\n/); + +// body(type=multipart-form) +const bodyMultipartForm = regex(/^body\s*\(\s*type\s*=\s*multipart-form\s*\)\s*\r?\n/); + // this regex allows the body end tag to start without a newline // currently the line parser consumes the last newline // todo: fix this @@ -121,10 +124,19 @@ const bodyFormUrlEncodedTag = between(bodyFormUrlEncoded)(bodyEndRelaxed)(keyval } }); +const bodyMultipartFormTag = between(bodyMultipartForm)(bodyEndRelaxed)(keyvalLines).map(([result]) => { + return { + body: { + multipartForm: result + } + } +}); + module.exports = { bodyJsonTag, bodyGraphqlTag, bodyTextTag, bodyXmlTag, - bodyFormUrlEncodedTag + bodyFormUrlEncodedTag, + bodyMultipartFormTag }; diff --git a/packages/bruno-lang/src/index.js b/packages/bruno-lang/src/index.js index 7568fd7dd..e5731e613 100644 --- a/packages/bruno-lang/src/index.js +++ b/packages/bruno-lang/src/index.js @@ -13,7 +13,8 @@ const { bodyGraphqlTag, bodyTextTag, bodyXmlTag, - bodyFormUrlEncodedTag + bodyFormUrlEncodedTag, + bodyMultipartFormTag } = require('./body-tag'); const bruToJson = (fileContents) => { @@ -26,6 +27,7 @@ const bruToJson = (fileContents) => { bodyTextTag, bodyXmlTag, bodyFormUrlEncodedTag, + bodyMultipartFormTag, anyChar ])); diff --git a/packages/bruno-lang/tests/fixtures/request.bru b/packages/bruno-lang/tests/fixtures/request.bru index 510c6a593..2e47885b0 100644 --- a/packages/bruno-lang/tests/fixtures/request.bru +++ b/packages/bruno-lang/tests/fixtures/request.bru @@ -44,3 +44,8 @@ body(type=form-url-encoded) 1 username john 0 password {{password}} /body + +body(type=multipart-form) + 1 username nash + 0 password governingdynamics +/body diff --git a/packages/bruno-lang/tests/parser.spec.js b/packages/bruno-lang/tests/parser.spec.js index 343afb719..a7e3e6a54 100644 --- a/packages/bruno-lang/tests/parser.spec.js +++ b/packages/bruno-lang/tests/parser.spec.js @@ -68,6 +68,18 @@ describe('bruToJson', () => { "key": "password", "value": "{{password}}" } + ], + "multipartForm": [ + { + "enabled": "1", + "key": "username", + "value": "nash" + }, + { + "enabled": "0", + "key": "password", + "value": "governingdynamics" + } ] } });