mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(editor): Fix importing curl commands with comma (#18409)
Co-authored-by: Your Name <you@example.com>
This commit is contained in:
@@ -474,6 +474,14 @@ describe('useImportCurlCommand', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
test('Should parse cURL command with a comma in query parameter value', () => {
|
||||
const curl = 'curl "https://example.com?bla=blu,bli"';
|
||||
const parameters = toHttpNodeParameters(curl);
|
||||
expect(parameters.url).toBe('https://example.com');
|
||||
expect(parameters.sendQuery).toBe(true);
|
||||
expect(parameters.queryParameters?.parameters).toEqual([{ name: 'bla', value: 'blu,bli' }]);
|
||||
});
|
||||
|
||||
test('Should parse cURL command with custom header and no content type', () => {
|
||||
const curl = 'curl -X GET https://reqbin.com/echo -H "Authorization: Bearer token"';
|
||||
const parameters = toHttpNodeParameters(curl);
|
||||
|
||||
@@ -243,12 +243,24 @@ export const toHttpNodeParameters = (curlCommand: string): HttpNodeParameters =>
|
||||
headers.authorization = `Basic ${encodeBasicAuthentication(user, pass)}`;
|
||||
}
|
||||
|
||||
// curlconverter does not parse query parameters correctly if they contain commas or semicolons
|
||||
// so we need to parse it again
|
||||
const url = new URL(curlJson.url);
|
||||
const queries = curlJson.queries ?? {};
|
||||
for (const [key, value] of url.searchParams) {
|
||||
queries[key] = value;
|
||||
}
|
||||
|
||||
url.search = '';
|
||||
// URL automatically adds a trailing slash if the path is empty
|
||||
const urlString = url.pathname === '/' ? url.href.slice(0, -1) : url.href;
|
||||
|
||||
const httpNodeParameters: HttpNodeParameters = {
|
||||
url: curlJson.url,
|
||||
url: urlString,
|
||||
authentication: 'none',
|
||||
method: curlJson.method.toUpperCase(),
|
||||
...extractHeaders({ ...headers, ...mapCookies(curlJson.cookies) }),
|
||||
...extractQueries(curlJson.queries),
|
||||
...extractQueries(queries),
|
||||
options: {
|
||||
redirect: {
|
||||
redirect: {},
|
||||
|
||||
Reference in New Issue
Block a user