fix(1548): correct import of escaped curl string (#1549)

This commit is contained in:
Igor Gulyayev 2024-02-08 12:08:02 -08:00 committed by GitHub
parent 7cf5f0d612
commit 808af3c19a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -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"
}
});
});
});

View File

@ -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, '');