mirror of
https://github.com/usebruno/bruno.git
synced 2024-12-22 14:41:04 +01:00
fix: fixed parser issue related to env variables #97
This commit is contained in:
parent
cac9f9aef4
commit
013abeaa80
@ -6,16 +6,18 @@ const grammar = ohm.grammar(`Bru {
|
||||
|
||||
nl = "\\r"? "\\n"
|
||||
st = " " | "\\t"
|
||||
stnl = st | nl
|
||||
tagend = nl "}"
|
||||
validkey = ~(st | ":") any
|
||||
validvalue = ~nl any
|
||||
optionalnl = ~tagend nl
|
||||
keychar = ~(tagend | st | nl | ":") any
|
||||
valuechar = ~(nl | tagend) any
|
||||
|
||||
// Dictionary Blocks
|
||||
dictionary = st* "{" pairlist? tagend
|
||||
pairlist = nl* pair (~tagend nl pair)* (~tagend space)*
|
||||
pair = st* key st* ":" st* value? st*
|
||||
key = ~tagend validkey*
|
||||
value = ~tagend validvalue*
|
||||
pairlist = optionalnl* pair (~tagend stnl* pair)* (~tagend space)*
|
||||
pair = st* key st* ":" st* value st*
|
||||
key = keychar*
|
||||
value = valuechar*
|
||||
|
||||
vars = "vars" dictionary
|
||||
}`);
|
||||
@ -68,7 +70,7 @@ const sem = grammar.createSemantics().addAttribute('ast', {
|
||||
},
|
||||
pair(_1, key, _2, _3, _4, value, _5) {
|
||||
let res = {};
|
||||
res[key.ast] = _.get(value, 'ast[0]', '');
|
||||
res[key.ast] = value.ast ? value.ast.trim() : '';
|
||||
return res;
|
||||
},
|
||||
key(chars) {
|
||||
|
@ -85,4 +85,33 @@ vars {
|
||||
|
||||
expect(output).toEqual(expected);
|
||||
});
|
||||
|
||||
it("should parse vars with empty values", () => {
|
||||
const input = `
|
||||
vars {
|
||||
url:
|
||||
phone:
|
||||
api-key:
|
||||
}
|
||||
`;
|
||||
|
||||
const output = parser(input);
|
||||
const expected = {
|
||||
"variables": [{
|
||||
"name": "url",
|
||||
"value": "",
|
||||
"enabled" : true,
|
||||
}, {
|
||||
"name": "phone",
|
||||
"value": "",
|
||||
"enabled" : true,
|
||||
}, {
|
||||
"name": "api-key",
|
||||
"value": "",
|
||||
"enabled" : true,
|
||||
}]
|
||||
};
|
||||
|
||||
expect(output).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user