From 405b50edcdfc9adb2e1369675530ac2716c5a8eb Mon Sep 17 00:00:00 2001 From: Anoop M D Date: Sun, 22 Jan 2023 00:35:58 +0530 Subject: [PATCH] fix: support parsing of empty urls in bru files --- packages/bruno-lang/src/inline-tag.js | 15 ++++++++--- packages/bruno-lang/tests/bru-to-json.spec.js | 25 +++++++++++++++++++ 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/packages/bruno-lang/src/inline-tag.js b/packages/bruno-lang/src/inline-tag.js index 03391e4c..bb738708 100644 --- a/packages/bruno-lang/src/inline-tag.js +++ b/packages/bruno-lang/src/inline-tag.js @@ -1,14 +1,14 @@ const { sequenceOf, - whitespace, str, - lookAhead, + regex, choice, endOfInput, everyCharUntil } = require("arcsecond"); -const newline = lookAhead(str("\n")); +const whitespace = regex(/^[ \t]*/) +const newline = regex(/^\r?\n/); const newLineOrEndOfInput = choice([endOfInput, newline]); const inlineTag = sequenceOf([ @@ -21,8 +21,15 @@ const inlineTag = sequenceOf([ str('body-mode') ]), whitespace, - everyCharUntil(newLineOrEndOfInput) + choice([ + newline, + everyCharUntil(newLineOrEndOfInput) + ]) ]).map(([key, _, val]) => { + if(val === '\n' || val === '\r\n') { + val = ''; + } + if(key === 'body-mode') { return { body: { diff --git a/packages/bruno-lang/tests/bru-to-json.spec.js b/packages/bruno-lang/tests/bru-to-json.spec.js index 6ec41128..98919b6c 100644 --- a/packages/bruno-lang/tests/bru-to-json.spec.js +++ b/packages/bruno-lang/tests/bru-to-json.spec.js @@ -89,4 +89,29 @@ describe('bruToJson', () => { }); }); +describe('jsonToBru - should parse bru file having empty url', () => { + const requestFile = `name Send Bulk SMS +method GET +url +type http-request +body-mode none +seq 1 +`; + it('should parse .bru file having empty url', () => { + const result = bruToJson(requestFile); + + expect(result).toEqual({ + type: 'http-request', + name: 'Send Bulk SMS', + seq: 1, + request: { + method: 'GET', + url: '', + params: [], + headers: [], + body: { mode: 'none' } + } + }); + }); +});