[PR #5828] fix(curl): properly handle ANSI-C quoted strings ($'...') in cURL import #5369

Open
opened 2026-03-17 02:49:20 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5828
Author: @kaigritun
Created: 2/3/2026
Status: 🔄 Open

Base: mainHead: fix/ansi-c-curl-import


📝 Commits (2)

  • 0a181c7 fix(curl): properly handle ANSI-C quoted strings ($'...') in cURL import
  • 2f9e8db fix: address Copilot review feedback

📊 Changes

2 files changed (+123 additions, -3 deletions)

View changed files

📝 packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js (+53 -0)
📝 packages/hoppscotch-common/src/helpers/curl/sub_helpers/preproc.ts (+70 -3)

📄 Description

Summary

Fixes #5728

The cURL import was failing to parse commands containing ANSI-C quoted strings ($'...'), which are commonly used when copying cURL commands from browser DevTools. The previous implementation simply stripped the $ prefix without processing the escape sequences inside.

Changes

Added proper ANSI-C escape sequence handling in preproc.ts:

  • Standard escapes: \n, \t, \r, \\, \', \", \a, \b, \e, \f, \v
  • Octal escapes: \nnn (1-3 digits)
  • Hex escapes: \xHH
  • Unicode escapes: \uHHHH

The processed content is then converted to a double-quoted string with proper escaping for the yargs parser.

Testing

Added a test case for basic ANSI-C quoted string handling. Existing tests pass (sample #12 was already failing due to a pre-existing multipart form data parsing issue unrelated to this change).

Example

Before this fix:

curl 'https://api.example.com' --data-raw $'{"key": "value\nwith newline"}'

Would fail to import or produce incorrect results.

After this fix:
The command is correctly parsed with the escape sequences properly processed.


Summary by cubic

Fixes cURL import failures for ANSI‑C quoted strings ($'...') by evaluating escape sequences and converting them to regular quoted strings. Commands copied from browser DevTools now import with the correct body content.

  • Bug Fixes
    • Parse $'...' with a single-pass escape handler (standard, octal, hex, unicode) and emit safely escaped double-quoted strings for yargs.
    • Added a test for ANSI‑C quoting; existing tests still pass.

Written for commit 2f9e8db476. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5828 **Author:** [@kaigritun](https://github.com/kaigritun) **Created:** 2/3/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/ansi-c-curl-import` --- ### 📝 Commits (2) - [`0a181c7`](https://github.com/hoppscotch/hoppscotch/commit/0a181c7748acf9556c6a05b5acb8fce89725a628) fix(curl): properly handle ANSI-C quoted strings ($'...') in cURL import - [`2f9e8db`](https://github.com/hoppscotch/hoppscotch/commit/2f9e8db476f5f1c99f993269b18f922ec1f6ed47) fix: address Copilot review feedback ### 📊 Changes **2 files changed** (+123 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-common/src/helpers/curl/__tests__/curlparser.spec.js` (+53 -0) 📝 `packages/hoppscotch-common/src/helpers/curl/sub_helpers/preproc.ts` (+70 -3) </details> ### 📄 Description ## Summary Fixes #5728 The cURL import was failing to parse commands containing ANSI-C quoted strings (`$'...'`), which are commonly used when copying cURL commands from browser DevTools. The previous implementation simply stripped the `$` prefix without processing the escape sequences inside. ## Changes Added proper ANSI-C escape sequence handling in `preproc.ts`: - Standard escapes: `\n`, `\t`, `\r`, `\\`, `\'`, `\"`, `\a`, `\b`, `\e`, `\f`, `\v` - Octal escapes: `\nnn` (1-3 digits) - Hex escapes: `\xHH` - Unicode escapes: `\uHHHH` The processed content is then converted to a double-quoted string with proper escaping for the yargs parser. ## Testing Added a test case for basic ANSI-C quoted string handling. Existing tests pass (sample #12 was already failing due to a pre-existing multipart form data parsing issue unrelated to this change). ## Example Before this fix: ```bash curl 'https://api.example.com' --data-raw $'{"key": "value\nwith newline"}' ``` Would fail to import or produce incorrect results. After this fix: The command is correctly parsed with the escape sequences properly processed. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes cURL import failures for ANSI‑C quoted strings ($'...') by evaluating escape sequences and converting them to regular quoted strings. Commands copied from browser DevTools now import with the correct body content. - **Bug Fixes** - Parse $'...' with a single-pass escape handler (standard, octal, hex, unicode) and emit safely escaped double-quoted strings for yargs. - Added a test for ANSI‑C quoting; existing tests still pass. <sup>Written for commit 2f9e8db476f5f1c99f993269b18f922ec1f6ed47. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5369
No description provided.