forked from extern/bruno
fix: support parsing of empty urls in bru files
This commit is contained in:
parent
fff540010e
commit
405b50edcd
@ -1,14 +1,14 @@
|
||||
const {
|
||||
sequenceOf,
|
||||
whitespace,
|
||||
str,
|
||||
lookAhead,
|
||||
regex,
|
||||
choice,
|
||||
endOfInput,
|
||||
everyCharUntil
|
||||
} = require("arcsecond");
|
||||
|
||||
const newline = lookAhead(str("\n"));
|
||||
const whitespace = regex(/^[ \t]*/)
|
||||
const newline = regex(/^\r?\n/);
|
||||
const newLineOrEndOfInput = choice([endOfInput, newline]);
|
||||
|
||||
const inlineTag = sequenceOf([
|
||||
@ -21,8 +21,15 @@ const inlineTag = sequenceOf([
|
||||
str('body-mode')
|
||||
]),
|
||||
whitespace,
|
||||
everyCharUntil(newLineOrEndOfInput)
|
||||
choice([
|
||||
newline,
|
||||
everyCharUntil(newLineOrEndOfInput)
|
||||
])
|
||||
]).map(([key, _, val]) => {
|
||||
if(val === '\n' || val === '\r\n') {
|
||||
val = '';
|
||||
}
|
||||
|
||||
if(key === 'body-mode') {
|
||||
return {
|
||||
body: {
|
||||
|
@ -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' }
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user