mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-25 09:23:17 +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)
|
// body(type=xml)
|
||||||
const bodyXmlBegin = regex(/^body\s*\(\s*type\s*=\s*xml\s*\)\s*\r?\n/);
|
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 bodyEnd = regex(/^[\r?\n]+\/body\s*[\r?\n]*/);
|
||||||
|
|
||||||
const bodyJsonTag = between(bodyJsonBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyJson) => {
|
const bodyJsonTag = between(bodyJsonBegin)(bodyEnd)(everyCharUntil(bodyEnd)).map((bodyJson) => {
|
||||||
@ -108,6 +105,12 @@ const line = sequenceOf([
|
|||||||
const lines = many(line);
|
const lines = many(line);
|
||||||
const keyvalLines = sepBy(newline)(lines);
|
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
|
// this regex allows the body end tag to start without a newline
|
||||||
// currently the line parser consumes the last newline
|
// currently the line parser consumes the last newline
|
||||||
// todo: fix this
|
// 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 = {
|
module.exports = {
|
||||||
bodyJsonTag,
|
bodyJsonTag,
|
||||||
bodyGraphqlTag,
|
bodyGraphqlTag,
|
||||||
bodyTextTag,
|
bodyTextTag,
|
||||||
bodyXmlTag,
|
bodyXmlTag,
|
||||||
bodyFormUrlEncodedTag
|
bodyFormUrlEncodedTag,
|
||||||
|
bodyMultipartFormTag
|
||||||
};
|
};
|
||||||
|
@ -13,7 +13,8 @@ const {
|
|||||||
bodyGraphqlTag,
|
bodyGraphqlTag,
|
||||||
bodyTextTag,
|
bodyTextTag,
|
||||||
bodyXmlTag,
|
bodyXmlTag,
|
||||||
bodyFormUrlEncodedTag
|
bodyFormUrlEncodedTag,
|
||||||
|
bodyMultipartFormTag
|
||||||
} = require('./body-tag');
|
} = require('./body-tag');
|
||||||
|
|
||||||
const bruToJson = (fileContents) => {
|
const bruToJson = (fileContents) => {
|
||||||
@ -26,6 +27,7 @@ const bruToJson = (fileContents) => {
|
|||||||
bodyTextTag,
|
bodyTextTag,
|
||||||
bodyXmlTag,
|
bodyXmlTag,
|
||||||
bodyFormUrlEncodedTag,
|
bodyFormUrlEncodedTag,
|
||||||
|
bodyMultipartFormTag,
|
||||||
anyChar
|
anyChar
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
@ -44,3 +44,8 @@ body(type=form-url-encoded)
|
|||||||
1 username john
|
1 username john
|
||||||
0 password {{password}}
|
0 password {{password}}
|
||||||
/body
|
/body
|
||||||
|
|
||||||
|
body(type=multipart-form)
|
||||||
|
1 username nash
|
||||||
|
0 password governingdynamics
|
||||||
|
/body
|
||||||
|
@ -68,6 +68,18 @@ describe('bruToJson', () => {
|
|||||||
"key": "password",
|
"key": "password",
|
||||||
"value": "{{password}}"
|
"value": "{{password}}"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"multipartForm": [
|
||||||
|
{
|
||||||
|
"enabled": "1",
|
||||||
|
"key": "username",
|
||||||
|
"value": "nash"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"enabled": "0",
|
||||||
|
"key": "password",
|
||||||
|
"value": "governingdynamics"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user