Skip to content

Commit

Permalink
fix(1548): correct import of escaped curl string (#1549)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlwilk32 authored Feb 8, 2024
1 parent 7cf5f0d commit 808af3c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/bruno-app/src/utils/curl/curl-to-json.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,20 @@ describe('curlToJson', () => {
data: '{"email":"[email protected]","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"
}
});
});
});
3 changes: 3 additions & 0 deletions packages/bruno-app/src/utils/curl/parse-curl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');

Expand Down

0 comments on commit 808af3c

Please sign in to comment.