fix: support parsing of empty urls in bru files

This commit is contained in:
Anoop M D 2023-01-22 00:35:58 +05:30
parent fff540010e
commit 405b50edcd
2 changed files with 36 additions and 4 deletions

View File

@ -1,14 +1,14 @@
const { const {
sequenceOf, sequenceOf,
whitespace,
str, str,
lookAhead, regex,
choice, choice,
endOfInput, endOfInput,
everyCharUntil everyCharUntil
} = require("arcsecond"); } = require("arcsecond");
const newline = lookAhead(str("\n")); const whitespace = regex(/^[ \t]*/)
const newline = regex(/^\r?\n/);
const newLineOrEndOfInput = choice([endOfInput, newline]); const newLineOrEndOfInput = choice([endOfInput, newline]);
const inlineTag = sequenceOf([ const inlineTag = sequenceOf([
@ -21,8 +21,15 @@ const inlineTag = sequenceOf([
str('body-mode') str('body-mode')
]), ]),
whitespace, whitespace,
everyCharUntil(newLineOrEndOfInput) choice([
newline,
everyCharUntil(newLineOrEndOfInput)
])
]).map(([key, _, val]) => { ]).map(([key, _, val]) => {
if(val === '\n' || val === '\r\n') {
val = '';
}
if(key === 'body-mode') { if(key === 'body-mode') {
return { return {
body: { body: {

View File

@ -89,4 +89,29 @@ describe('bruToJson', () => {
}); });
}); });
describe('jsonToBru - should parse bru file having empty url', () => {
const requestFile = `name Send Bulk SMS
method GET
url
type http-request
body-mode none
seq 1
`;
it('should parse .bru file having empty url', () => {
const result = bruToJson(requestFile);
expect(result).toEqual({
type: 'http-request',
name: 'Send Bulk SMS',
seq: 1,
request: {
method: 'GET',
url: '',
params: [],
headers: [],
body: { mode: 'none' }
}
});
});
});