feat: bru lang - allow parsing empty header values

This commit is contained in:
Anoop M D 2023-02-03 23:02:16 +05:30
parent a21615a5fb
commit 118ceacf46
2 changed files with 21 additions and 4 deletions

View File

@ -12,7 +12,7 @@ const grammar = ohm.grammar(`Bru {
headers = "headers" st* "{" pairlist? tagend
pairlist = nl* pair (~tagend nl pair)* (~tagend space)*
pair = st* key st* ":" st* value st*
pair = st* key st* ":" st* value? st*
key = ~tagend validkey*
value = ~tagend validvalue*
@ -58,7 +58,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
},
pair(_1, key, _2, _3, _4, value, _5) {
let res = {};
res[key.ast] = value.ast;
res[key.ast] = _.get(value, 'ast[0]', '');
return res;
},
key(chars) {

View File

@ -56,6 +56,23 @@ headers {
assertSingleHeader(input);
});
it("should parse single header with empty value", () => {
const input = `
headers {
hello:
}`;
const output = bruToJsonV2(input);
const expected = {
"headers": [{
"name": "hello",
"value": "",
"enabled": true
}]
};
expect(output).toEqual(expected);
});
it("should parse multi headers", () => {
const input = `
headers {