mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-25 16:18:56 +01:00
feat: bruno lang now supports parsing text only multipart form data
This commit is contained in:
parent
4eed999db1
commit
8dab9268f2
@ -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
|
||||
};
|
||||
|
@ -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
|
||||
]));
|
||||
|
||||
|
@ -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
|
||||
|
@ -68,6 +68,18 @@ describe('bruToJson', () => {
|
||||
"key": "password",
|
||||
"value": "{{password}}"
|
||||
}
|
||||
],
|
||||
"multipartForm": [
|
||||
{
|
||||
"enabled": "1",
|
||||
"key": "username",
|
||||
"value": "nash"
|
||||
},
|
||||
{
|
||||
"enabled": "0",
|
||||
"key": "password",
|
||||
"value": "governingdynamics"
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user