feat: deprecated form-url-encoded in favour of form-urlencoded in body type in bru lang

This commit is contained in:
Anoop M D 2023-01-22 23:49:25 +05:30
parent 84ce75263b
commit 0c42298ce6
4 changed files with 30 additions and 7 deletions

View File

@ -55,10 +55,8 @@ script
/script
assert
{
"$res.data.order.items.length": 1,
"$res.data.orderNumber.isDefined": true
}
1 $res.data.order.items.length 1
1 $res.data.orderNumber.isDefined true
/assert
docs

View File

@ -85,8 +85,22 @@ const line = sequenceOf([
const lines = many(line);
const keyvalLines = sepBy(newline)(lines);
/**
* We have deprecated form-url-encoded type in body tag, it was a misspelling on my part
* The new type is form-urlencoded
*
* Very few peope would have used this. I launched this to the public on 22 Jan 2023
* And I am making the change on 23 Jan 2023
*
* This deprecated tag can be removed on 1 April 2023
*/
// body(type=form-url-encoded)
const bodyFormUrlEncoded = regex(/^body\s*\(\s*type\s*=\s*form-url-encoded\s*\)\s*\r?\n/);
const bodyFormUrlEncodedDeprecated = regex(/^body\s*\(\s*type\s*=\s*form-url-encoded\s*\)\s*\r?\n/);
// body(type=form-urlencoded)
const bodyFormUrlEncoded = regex(/^body\s*\(\s*type\s*=\s*form-urlencoded\s*\)\s*\r?\n/);
// body(type=multipart-form)
const bodyMultipartForm = regex(/^body\s*\(\s*type\s*=\s*multipart-form\s*\)\s*\r?\n/);
@ -96,6 +110,14 @@ const bodyMultipartForm = regex(/^body\s*\(\s*type\s*=\s*multipart-form\s*\)\s*\
// todo: fix this
const bodyEndRelaxed = regex(/^[\r?\n]*\/body\s*[\r?\n]*/);
const bodyFormUrlEncodedTagDeprecated = between(bodyFormUrlEncodedDeprecated)(bodyEndRelaxed)(keyvalLines).map(([result]) => {
return {
body: {
formUrlEncoded: result
}
}
});
const bodyFormUrlEncodedTag = between(bodyFormUrlEncoded)(bodyEndRelaxed)(keyvalLines).map(([result]) => {
return {
body: {
@ -117,6 +139,7 @@ module.exports = {
bodyGraphqlTag,
bodyTextTag,
bodyXmlTag,
bodyFormUrlEncodedTagDeprecated,
bodyFormUrlEncodedTag,
bodyMultipartFormTag
};

View File

@ -18,6 +18,7 @@ const {
bodyGraphqlTag,
bodyTextTag,
bodyXmlTag,
bodyFormUrlEncodedTagDeprecated,
bodyFormUrlEncodedTag,
bodyMultipartFormTag
} = require('./body-tag');
@ -33,6 +34,7 @@ const bruToJson = (fileContents) => {
bodyGraphqlTag,
bodyTextTag,
bodyXmlTag,
bodyFormUrlEncodedTagDeprecated,
bodyFormUrlEncodedTag,
bodyMultipartFormTag,
scriptTag,
@ -155,7 +157,7 @@ ${indentString(body.xml)}
if(body && body.formUrlEncoded && body.formUrlEncoded.length) {
bru += `
body(type=form-url-encoded)
body(type=form-urlencoded)
${body.formUrlEncoded.map(item => ` ${item.enabled ? 1 : 0} ${item.name} ${item.value}`).join('\n')}
/body
`;

View File

@ -40,7 +40,7 @@ body(type=xml)
<body>back to the ice age</body>
/body
body(type=form-url-encoded)
body(type=form-urlencoded)
1 username john
0 password {{password}}
/body