mirror of
https://github.com/usebruno/bruno.git
synced 2025-02-02 02:49:48 +01:00
feat: bru lang - allow parsing empty header values
This commit is contained in:
parent
a21615a5fb
commit
118ceacf46
@ -12,7 +12,7 @@ const grammar = ohm.grammar(`Bru {
|
|||||||
headers = "headers" st* "{" pairlist? tagend
|
headers = "headers" st* "{" pairlist? tagend
|
||||||
|
|
||||||
pairlist = nl* pair (~tagend nl pair)* (~tagend space)*
|
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*
|
key = ~tagend validkey*
|
||||||
value = ~tagend validvalue*
|
value = ~tagend validvalue*
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
|||||||
},
|
},
|
||||||
pair(_1, key, _2, _3, _4, value, _5) {
|
pair(_1, key, _2, _3, _4, value, _5) {
|
||||||
let res = {};
|
let res = {};
|
||||||
res[key.ast] = value.ast;
|
res[key.ast] = _.get(value, 'ast[0]', '');
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
key(chars) {
|
key(chars) {
|
||||||
|
@ -56,6 +56,23 @@ headers {
|
|||||||
assertSingleHeader(input);
|
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", () => {
|
it("should parse multi headers", () => {
|
||||||
const input = `
|
const input = `
|
||||||
headers {
|
headers {
|
||||||
|
Loading…
Reference in New Issue
Block a user