mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-24 05:51:22 +02: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"
|
nl = "\\r"? "\\n"
|
||||||
st = " " | "\\t"
|
st = " " | "\\t"
|
||||||
|
stnl = st | nl
|
||||||
tagend = nl "}"
|
tagend = nl "}"
|
||||||
validkey = ~(st | ":") any
|
optionalnl = ~tagend nl
|
||||||
validvalue = ~nl any
|
keychar = ~(tagend | st | nl | ":") any
|
||||||
|
valuechar = ~(nl | tagend) any
|
||||||
|
|
||||||
// Dictionary Blocks
|
// Dictionary Blocks
|
||||||
dictionary = st* "{" pairlist? tagend
|
dictionary = st* "{" pairlist? tagend
|
||||||
pairlist = nl* pair (~tagend nl pair)* (~tagend space)*
|
pairlist = optionalnl* pair (~tagend stnl* pair)* (~tagend space)*
|
||||||
pair = st* key st* ":" st* value? st*
|
pair = st* key st* ":" st* value st*
|
||||||
key = ~tagend validkey*
|
key = keychar*
|
||||||
value = ~tagend validvalue*
|
value = valuechar*
|
||||||
|
|
||||||
vars = "vars" dictionary
|
vars = "vars" dictionary
|
||||||
}`);
|
}`);
|
||||||
@ -68,7 +70,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] = _.get(value, 'ast[0]', '');
|
res[key.ast] = value.ast ? value.ast.trim() : '';
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
key(chars) {
|
key(chars) {
|
||||||
|
@ -85,4 +85,33 @@ vars {
|
|||||||
|
|
||||||
expect(output).toEqual(expected);
|
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…
x
Reference in New Issue
Block a user