Skip to content

Commit

Permalink
fix: strip backslashes from curl when paste (#3376)
Browse files Browse the repository at this point in the history
Fixes #3375

The arguments parser we use missed a case with explicit backslashes and
I missed it in our tests. Here removed it with regex.
  • Loading branch information
TrySound authored May 18, 2024
1 parent ef01841 commit 2fd7c6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 3 additions & 5 deletions apps/builder/app/builder/features/settings-panel/curl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ test("support url", () => {
expect(parseCurl(`curl 'https://my-url/hello-world'`)).toEqual(result);
});

test("support multiline", () => {
test("support multiline command with backslashes", () => {
expect(
parseCurl(`curl \
parseCurl(`curl \\
'https://my-url/hello-world'
`)
).toEqual({
Expand Down Expand Up @@ -114,9 +114,7 @@ test("support text body with explicit method", () => {
test("support json body", () => {
expect(
parseCurl(
`curl https://my-url/hello-world \
--header 'content-type: application/json' \
--data '{"param":"value"}'`
`curl https://my-url/hello-world --header 'content-type: application/json' --data '{"param":"value"}'`
)
).toEqual({
url: "https://my-url/hello-world",
Expand Down
3 changes: 3 additions & 0 deletions apps/builder/app/builder/features/settings-panel/curl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ export type CurlRequest = Pick<
>;

export const parseCurl = (curl: string): undefined | CurlRequest => {
// remove backslash followed by newline
// https://github.com/astur/arrgv/issues/3
curl = curl.replaceAll(/\\(?=\s)/g, "");
let argv;
try {
argv = arrgv(curl);
Expand Down

0 comments on commit 2fd7c6d

Please sign in to comment.