diff --git a/packages/bruno-app/src/utils/importers/common.js b/packages/bruno-app/src/utils/importers/common.js index 12eb79f4d..3388c531f 100644 --- a/packages/bruno-app/src/utils/importers/common.js +++ b/packages/bruno-app/src/utils/importers/common.js @@ -50,8 +50,6 @@ export const updateUidsInCollection = (_collection) => { }; updateEnvUids(collection.environments); - console.log(collection); - return collection; }; diff --git a/packages/bruno-lang/v2/src/bruToJson.js b/packages/bruno-lang/v2/src/bruToJson.js index 00a6d83fd..6ff564fbf 100644 --- a/packages/bruno-lang/v2/src/bruToJson.js +++ b/packages/bruno-lang/v2/src/bruToJson.js @@ -33,22 +33,22 @@ const grammar = ohm.grammar(`Bru { stnl = st | nl tagend = nl "}" optionalnl = ~tagend nl - validkey = ~(st | ":") any - validvalue = ~nl any + keychar = ~(tagend | st | nl | ":") any + valuechar = ~(nl | tagend) any // Dictionary Blocks dictionary = st* "{" pairlist? tagend pairlist = optionalnl* pair (~tagend stnl* pair)* (~tagend space)* - pair = st* key st* ":" st* value? st* - key = ~tagend validkey* - value = ~tagend validvalue* + pair = st* key st* ":" st* value st* + key = keychar* + value = valuechar* // Dictionary for Assert Block assertdictionary = st* "{" assertpairlist? tagend assertpairlist = optionalnl* assertpair (~tagend stnl* assertpair)* (~tagend space)* - assertpair = st* assertkey st* ":" st* value? st* - assertkey = ~tagend assertvalidkey* - assertvalidkey = ~(":") any + assertpair = st* assertkey st* ":" st* value st* + assertkey = ~tagend assertkeychar* + assertkeychar = ~(tagend | nl | ":") any // Text Blocks textblock = textline (~tagend nl textline)* @@ -146,7 +146,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) { @@ -163,7 +163,7 @@ const sem = grammar.createSemantics().addAttribute('ast', { }, assertpair(_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; }, assertkey(chars) { diff --git a/packages/bruno-lang/v2/tests/dictionary.spec.js b/packages/bruno-lang/v2/tests/dictionary.spec.js index 27b2f9015..616010092 100644 --- a/packages/bruno-lang/v2/tests/dictionary.spec.js +++ b/packages/bruno-lang/v2/tests/dictionary.spec.js @@ -1,5 +1,5 @@ /** - * This test file is used to test the text parser. + * This test file is used to test the dictionary parser. */ const parser = require("../src/bruToJson"); @@ -117,6 +117,24 @@ headers { expect(output).toEqual(expected); }); + it("should parse empty url", () => { + const input = ` +get { + url: + body: json +}`; + + const output = parser(input); + const expected = { + "http": { + "url": "", + "method": "get", + "body": "json", + } + }; + expect(output).toEqual(expected); + }); + it("should throw error on invalid header", () => { const input = ` headers {