[GH-ISSUE #3967] [bug]: Import cUrl failed #1390

Open
opened 2026-03-16 20:08:54 +03:00 by kerem · 4 comments
Owner

Originally created by @AlexNeAuto on GitHub (Apr 8, 2024).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/3967

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

When i try to import cUrl with escape symbols
curl -X POST 'https://example.com' -H "User-Agent: loadmill/v9.92.0" -H "content-type: application/json" -d "{ \"API_KEY\": \"api_key\", \"API_SECRET\": \"secret\", \"Device\": {\"id\": \"1234567890\"} ,\"messageIds\": [\"message_1234567890\"], \"action\": \"accept\", \"raw\": \"{ \\\"test\\\": \\\"test\\\"}\" }"
i've doesn't get any error message, but if i cover safeParseJSOn function from ImportCurl component by try catch the error message is

Screenshot 2024-04-08 at 17 14 13
Error SyntaxError: Unterminated string in JSON at position 173 (line 1 column 174)
    at JSON.parse (<anonymous>)
    at json.ts:17:25
    at Module.tryCatch (chunk-7GXFONRI.js?v=4d8dafc1:400:18)
    at safeParseJSON (json.ts:15:5)
    at chunk-N5YTPUBR.js?v=4d8dafc1:144:25
    at parseBody (contentParser.ts:192:21)
    at body.ts:46:11
    at chunk-7GXFONRI.js?v=4d8dafc1:222:25
    at chunk-N5YTPUBR.js?v=4d8dafc1:259:19
    at pipe (chunk-N5YTPUBR.js?v=4d8dafc1:212:14)

I guess the problem is somewhere in FE side, it's serialized string again and i got something like this:
"curl -X POST 'https://example.com' -H \"User-Agent: loadmill/v9.92.0\" -H \"content-type: application/json\" -d \"{ \\\"API_KEY\\\": \\\"api_key\\\", \\\"API_SECRET\\\": \\\"secret\\\", \\\"Device\\\": {\\\"id\\\": \\\"1234567890\\\"} ,\\\"messageIds\\\": [\\\"message_1234567890\\\"], \\\"action\\\": \\\"accept\\\", \\\"raw\\\": \\\"{ \\\\\\\"test\\\\\\\": \\\\\\\"test\\\\\\\"}\\\" }\""

Steps to reproduce

Import cUrl
curl -X POST 'https://example.com' -H "User-Agent: loadmill/v9.92.0" -H "content-type: application/json" -d "{ \"API_KEY\": \"api_key\", \"API_SECRET\": \"secret\", \"Device\": {\"id\": \"1234567890\"} ,\"messageIds\": [\"message_1234567890\"], \"action\": \"accept\", \"raw\": \"{ \\\"test\\\": \\\"test\\\"}\" }"

Environment

Production

Version

Self-hosted

Originally created by @AlexNeAuto on GitHub (Apr 8, 2024). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/3967 ### Is there an existing issue for this? - [X] I have searched the existing issues ### Current behavior When i try to import cUrl with escape symbols ```curl -X POST 'https://example.com' -H "User-Agent: loadmill/v9.92.0" -H "content-type: application/json" -d "{ \"API_KEY\": \"api_key\", \"API_SECRET\": \"secret\", \"Device\": {\"id\": \"1234567890\"} ,\"messageIds\": [\"message_1234567890\"], \"action\": \"accept\", \"raw\": \"{ \\\"test\\\": \\\"test\\\"}\" }"``` i've doesn't get any error message, but if i cover `safeParseJSOn` function from ImportCurl component by try catch the error message is <img width="859" alt="Screenshot 2024-04-08 at 17 14 13" src="https://github.com/hoppscotch/hoppscotch/assets/106549594/65291ee1-30f6-4375-b695-71a10dd1a8da"> ``` Error SyntaxError: Unterminated string in JSON at position 173 (line 1 column 174) at JSON.parse (<anonymous>) at json.ts:17:25 at Module.tryCatch (chunk-7GXFONRI.js?v=4d8dafc1:400:18) at safeParseJSON (json.ts:15:5) at chunk-N5YTPUBR.js?v=4d8dafc1:144:25 at parseBody (contentParser.ts:192:21) at body.ts:46:11 at chunk-7GXFONRI.js?v=4d8dafc1:222:25 at chunk-N5YTPUBR.js?v=4d8dafc1:259:19 at pipe (chunk-N5YTPUBR.js?v=4d8dafc1:212:14) ``` I guess the problem is somewhere in FE side, it's serialized string again and i got something like this: ```"curl -X POST 'https://example.com' -H \"User-Agent: loadmill/v9.92.0\" -H \"content-type: application/json\" -d \"{ \\\"API_KEY\\\": \\\"api_key\\\", \\\"API_SECRET\\\": \\\"secret\\\", \\\"Device\\\": {\\\"id\\\": \\\"1234567890\\\"} ,\\\"messageIds\\\": [\\\"message_1234567890\\\"], \\\"action\\\": \\\"accept\\\", \\\"raw\\\": \\\"{ \\\\\\\"test\\\\\\\": \\\\\\\"test\\\\\\\"}\\\" }\""``` ### Steps to reproduce Import cUrl ```curl -X POST 'https://example.com' -H "User-Agent: loadmill/v9.92.0" -H "content-type: application/json" -d "{ \"API_KEY\": \"api_key\", \"API_SECRET\": \"secret\", \"Device\": {\"id\": \"1234567890\"} ,\"messageIds\": [\"message_1234567890\"], \"action\": \"accept\", \"raw\": \"{ \\\"test\\\": \\\"test\\\"}\" }"``` ### Environment Production ### Version Self-hosted
Author
Owner

@shipko commented on GitHub (Apr 11, 2024):

Hi!
I confirmed this bug. Also I can add another failed use case.

curl -X POST 'http://example.com:30101/api?external_postprocessing=true' -F 'images=@"/C:/test2.png"' -F 'metadata="{\"application\": \"app\", \"sessionId\": \"559b9fad-5dd2-4bd8-a071-6f07b7bbb7b3\"}";type=application/json'

Parameter metadata is not imported as json object, because not to checked type args.

<!-- gh-comment-id:2049849561 --> @shipko commented on GitHub (Apr 11, 2024): Hi! I confirmed this bug. Also I can add another failed use case. ``` curl -X POST 'http://example.com:30101/api?external_postprocessing=true' -F 'images=@"/C:/test2.png"' -F 'metadata="{\"application\": \"app\", \"sessionId\": \"559b9fad-5dd2-4bd8-a071-6f07b7bbb7b3\"}";type=application/json' ``` Parameter `metadata` is not imported as json object, because not to checked `type` args.
Author
Owner

@AlexNeAuto commented on GitHub (Apr 16, 2024):

@shipko is there will be any actions from the team about this issue?

<!-- gh-comment-id:2058821390 --> @AlexNeAuto commented on GitHub (Apr 16, 2024): @shipko is there will be any actions from the team about this issue?
Author
Owner

@liyasthomas commented on GitHub (Apr 16, 2024):

We'll get this issue fixed in the next immediate release candidate. Could you subscribe to this issue thread to get notified once the fix is live?

Meanwhile, if anyone would like to try this, feel free to open up a PR.

<!-- gh-comment-id:2058988701 --> @liyasthomas commented on GitHub (Apr 16, 2024): We'll get this issue fixed in the next immediate release candidate. Could you subscribe to this issue thread to get notified once the fix is live? Meanwhile, if anyone would like to try this, feel free to open up a PR.
Author
Owner

@shipko commented on GitHub (Apr 17, 2024):

@liyasthomas
I want to try fix this issue. But when I started a solving the problem I noticed that the problem lies in the yargs-parser/browser library.
After parse @AlexNeAuto curl command I get
"{ \"API_KEY\": \"api_key\", \"API_SECRET\": \"secret\", \"Device\": {\"id\": \"1234567890\"} ,\"messageIds\": [\"message_1234567890\"], \"action\": \"accept\", \"raw\": \"{ value of d parameter.

Also we have another failed curl command:
curl -X POST 'http://example.com:30101/api?external_postprocessing=true' -F 'images=@"/C:/test2.png"' -F 'metadata="{\"application\": \"app\", \"sessionId\": \"559b9fad-5dd2-4bd8-a071-6f07b7bbb7b3\"}";type=application/json'

And another issue https://github.com/hoppscotch/hoppscotch/issues/3901

I think this library is not suitable for us. A curl contains a lot of arguments with subtle logic, you can't just parse the arguments here.

Maybe we should start looking for an alternative library?

<!-- gh-comment-id:2061400332 --> @shipko commented on GitHub (Apr 17, 2024): @liyasthomas I want to try fix this issue. But when I started a solving the problem I noticed that the problem lies in the `yargs-parser/browser` library. After parse @AlexNeAuto curl command I get `"{ \"API_KEY\": \"api_key\", \"API_SECRET\": \"secret\", \"Device\": {\"id\": \"1234567890\"} ,\"messageIds\": [\"message_1234567890\"], \"action\": \"accept\", \"raw\": \"{` value of `d` parameter. Also we have another failed curl command: `curl -X POST 'http://example.com:30101/api?external_postprocessing=true' -F 'images=@"/C:/test2.png"' -F 'metadata="{\"application\": \"app\", \"sessionId\": \"559b9fad-5dd2-4bd8-a071-6f07b7bbb7b3\"}";type=application/json'` And another issue https://github.com/hoppscotch/hoppscotch/issues/3901 I think this library is not suitable for us. A curl contains a lot of arguments with subtle logic, you can't just parse the arguments here. Maybe we should start looking for an alternative library?
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#1390
No description provided.