diff --git a/packages/bruno-app/src/utils/curl/curl-to-json.spec.js b/packages/bruno-app/src/utils/curl/curl-to-json.spec.js index c8f7d1c03..2704bd4c5 100644 --- a/packages/bruno-app/src/utils/curl/curl-to-json.spec.js +++ b/packages/bruno-app/src/utils/curl/curl-to-json.spec.js @@ -59,4 +59,20 @@ describe('curlToJson', () => { data: '{"email":"test@usebruno.com","password":"test"}' }); }); + + it('should accept escaped curl string', () => { + const curlCommand = `curl https://www.usebruno.com + -H $'cookie: val_1=\'\'; val_2=\\^373:0\\^373:0; val_3=\u0068\u0065\u006C\u006C\u006F' + `; + const result = curlToJson(curlCommand); + + expect(result).toEqual({ + url: 'https://www.usebruno.com', + raw_url: 'https://www.usebruno.com', + method: 'get', + headers: { + cookie: "val_1=''; val_2=\\^373:0\\^373:0; val_3=hello" + } + }); + }); }); diff --git a/packages/bruno-app/src/utils/curl/parse-curl.js b/packages/bruno-app/src/utils/curl/parse-curl.js index b7f6572f7..0ae97a1fb 100644 --- a/packages/bruno-app/src/utils/curl/parse-curl.js +++ b/packages/bruno-app/src/utils/curl/parse-curl.js @@ -12,6 +12,9 @@ import * as querystring from 'query-string'; import yargs from 'yargs-parser'; const parseCurlCommand = (curlCommand) => { + // catch escape sequences (e.g. -H $'cookie: it=\'\'') + curlCommand = curlCommand.replace(/\$('.*')/g, (match, group) => group); + // Remove newlines (and from continuations) curlCommand = curlCommand.replace(/\\\r|\\\n/g, '');