Skip to content

Commit 62c212b

Browse files
authored
fix: missing = when import -d from curl (#9434)
1 parent 66aad51 commit 62c212b

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

packages/insomnia/src/main/importers/importers/curl.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Parameter } from '../entities';
55
import { convert } from './curl';
66

77
describe('curl', () => {
8-
describe('cURL --data flags', () => {
8+
describe("cURL --data flags -H 'Content-Type: application/x-www-form-urlencoded'", () => {
99
it.each([
1010
// -d
1111
{ flag: '-d', inputs: ['key=value'], expected: [{ name: 'key', value: 'value' }] },
@@ -207,6 +207,27 @@ describe('curl', () => {
207207
},
208208
);
209209
});
210+
211+
describe('cURL --data flags', () => {
212+
it.each([{ flag: '-d', inputs: ['key=value'], expected: 'key=value' }])(
213+
'handles %p correctly',
214+
async ({ flag, inputs, expected }: { flag: string; inputs: string[]; expected: string }) => {
215+
const flaggedInputs = inputs.map(input => `${flag} ${quote([input])}`).join(' ');
216+
const rawData = `curl -X POST https://example.com
217+
${flaggedInputs}
218+
`;
219+
220+
expect(convert(rawData)).toMatchObject([
221+
{
222+
body: {
223+
text: expected,
224+
},
225+
},
226+
]);
227+
},
228+
);
229+
});
230+
210231
describe('cURL -H flags', () => {
211232
it.each([
212233
{ flag: '-H', inputs: ['X-Host: example.com'], expected: [{ name: 'X-Host', value: 'example.com' }] },

packages/insomnia/src/main/importers/importers/curl.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ const importCommand = (parseEntries: ParseEntry[]): ImportRequest => {
191191

192192
if (dataParameters.length !== 0 && bodyAsGET) {
193193
parameters.push(...dataParameters);
194-
} else if (dataParameters && mimeType === 'application/x-www-form-urlencoded') {
194+
} else if (dataParameters.length !== 0 && mimeType === 'application/x-www-form-urlencoded') {
195195
body = {
196196
mimeType,
197197
params: dataParameters.map(parameter => ({
@@ -202,7 +202,9 @@ const importCommand = (parseEntries: ParseEntry[]): ImportRequest => {
202202
};
203203
} else if (dataParameters.length !== 0) {
204204
body = {
205-
text: dataParameters.map(parameter => `${parameter.name}${parameter.value}`).join('&'),
205+
text: dataParameters
206+
.map(parameter => (parameter.name ? `${parameter.name}=${parameter.value}` : parameter.value))
207+
.join('&'),
206208
mimeType: mimeType || '',
207209
};
208210
} else if (formDataParams.length) {

0 commit comments

Comments
 (0)