[GH-ISSUE #2424] [bug]: cURl paser body error #820

Closed
opened 2026-03-16 17:18:58 +03:00 by kerem · 10 comments
Owner

Originally created by @renmu123 on GitHub (Jun 13, 2022).
Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2424

Originally assigned to: @AndrewBastin, @John-Weak on GitHub.

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

when I import cURL, the bosy parse error.

Steps to reproduce

Click to 'import cURL'
input: curl

curl 'http://api.test' \
  -H 'Accept: application/json, text/plain, */*' \
  -H 'Accept-Language: zh,zh-CN;q=0.9,en;q=0.8,zh-TW;q=0.7,ja;q=0.6' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'DNT: 1' \
  -H 'Origin: http://localhost:8000' \
  -H 'Proxy-Connection: keep-alive' \
  -H 'Referer: http://localhost:8000/' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \
  --data-raw 'name=11&logistics_id=4&port_id=3' \
  --compressed \
  --insecure

Body was translate to "name: 11&logistics_id" instead of
"name: 11
logistics_id: 4
port_id: 3'"

Environment

Release

Version

Local

Originally created by @renmu123 on GitHub (Jun 13, 2022). Original GitHub issue: https://github.com/hoppscotch/hoppscotch/issues/2424 Originally assigned to: @AndrewBastin, @John-Weak on GitHub. ### Is there an existing issue for this? - [X] I have searched the existing issues ### Current behavior when I import cURL, the bosy parse error. ### Steps to reproduce Click to 'import cURL' input: curl ``` curl 'http://api.test' \ -H 'Accept: application/json, text/plain, */*' \ -H 'Accept-Language: zh,zh-CN;q=0.9,en;q=0.8,zh-TW;q=0.7,ja;q=0.6' \ -H 'Content-Type: application/x-www-form-urlencoded' \ -H 'DNT: 1' \ -H 'Origin: http://localhost:8000' \ -H 'Proxy-Connection: keep-alive' \ -H 'Referer: http://localhost:8000/' \ -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' \ --data-raw 'name=11&logistics_id=4&port_id=3' \ --compressed \ --insecure ``` Body was translate to "name: 11&logistics_id" instead of "name: 11 logistics_id: 4 port_id: 3'" ### Environment Release ### Version Local
kerem 2026-03-16 17:18:58 +03:00
Author
Owner

@AndrewBastin commented on GitHub (Jun 13, 2022):

cc: @kyteinsky

<!-- gh-comment-id:1153514942 --> @AndrewBastin commented on GitHub (Jun 13, 2022): cc: @kyteinsky
Author
Owner

@John-Weak commented on GitHub (Jun 15, 2022):

@AndrewBastin Can you please assign this to me?

Also I was looking into tests of curl parser and found out that only one test contains --data-raw ,
which is of type --data-raw '{"id":4,"crm_company_id":4,"industry_primary_id":2,"contacts":[]}',

Should I open a pull request to include the problematic type format:
--data-raw 'name=11&logistics_id=4&port_id=3'

<!-- gh-comment-id:1156026148 --> @John-Weak commented on GitHub (Jun 15, 2022): @AndrewBastin Can you please assign this to me? Also I was looking into tests of curl parser and found out that only one test contains **--data-raw** , which is of type --data-raw '{"id":4,"crm_company_id":4,"industry_primary_id":2,"contacts":[]}', Should I open a pull request to include the problematic type format: --data-raw 'name=11&logistics_id=4&port_id=3'
Author
Owner

@kyteinsky commented on GitHub (Jun 15, 2022):

@John-Weak I am afraid that's not the issue here. The curl parser replaces all --data-raw tags with -d tags. But yeah one test sure is missing.

Last I looked into it there were issues with this function and this block getting executed. The problem is I don't remember why that else if block is there in the first place (@AndrewBastin would be smiling rn).

<!-- gh-comment-id:1156033062 --> @kyteinsky commented on GitHub (Jun 15, 2022): @John-Weak I am afraid that's not the issue here. The curl parser replaces all `--data-raw` tags with `-d` tags. But yeah one test sure is missing. Last I looked into it there were issues with [this function](https://github.com/hoppscotch/hoppscotch/blob/main/packages/hoppscotch-app/helpers/curl/curlparser.ts#L75) and [this block](https://github.com/hoppscotch/hoppscotch/blob/main/packages/hoppscotch-app/helpers/curl/curlparser.ts#L94-L101) getting executed. The problem is I don't remember why that else if block is there in the first place (@AndrewBastin would be smiling rn).
Author
Owner

@John-Weak commented on GitHub (Jun 15, 2022):

As per my view I think this pair function is the issue,

After console logging the return value of this function for the first test:
image

But for problematic case:
image

Am I on the correct path?

<!-- gh-comment-id:1156075513 --> @John-Weak commented on GitHub (Jun 15, 2022): As per my view I think this [pair function](https://github.com/hoppscotch/hoppscotch/blob/2d0bd48e0007009f7a2e945e606f25b8f8f59bb2/packages/hoppscotch-app/helpers/curl/curlparser.ts#L75-L87) is the issue, After console logging the return value of this function for the [first test](https://github.com/hoppscotch/hoppscotch/blob/2d0bd48e0007009f7a2e945e606f25b8f8f59bb2/packages/hoppscotch-app/helpers/curl/__tests__/curlparser.spec.js#L9-L14): ![image](https://user-images.githubusercontent.com/18065510/173764581-ab4887a0-ee0a-49c2-8a91-8aeb2218cd5c.png) But for problematic case: ![image](https://user-images.githubusercontent.com/18065510/173764740-7bceefbf-7d0a-42d2-9506-67828db3508d.png) Am I on the correct path?
Author
Owner

@kyteinsky commented on GitHub (Jun 15, 2022):

Yup totally! My guess is that the Array.isArray condition is not working properly. See if you can get part to work.

And bonus if you can find what that else if block does and place a small comment there.

<!-- gh-comment-id:1156161256 --> @kyteinsky commented on GitHub (Jun 15, 2022): Yup totally! My guess is that the `Array.isArray` condition is not working properly. See if you can get part to work. And bonus if you can find what that `else if` block does and place a small comment there.
Author
Owner

@AndrewBastin commented on GitHub (Jun 15, 2022):

@John-Weak I am assigning this issue to you.

<!-- gh-comment-id:1156205923 --> @AndrewBastin commented on GitHub (Jun 15, 2022): @John-Weak I am assigning this issue to you.
Author
Owner

@John-Weak commented on GitHub (Jun 16, 2022):

Upon further inspection I think I will need to fix this preprocess function so that It handles the case where & is presesnt
(example name=11&logistics_id=4&port_id=3).

Since the rawData is derived from parser,the only way to patch this is to modify the preprocess function

<!-- gh-comment-id:1157230678 --> @John-Weak commented on GitHub (Jun 16, 2022): Upon further inspection I think I will need to fix this [preprocess function](https://github.com/hoppscotch/hoppscotch/blob/2d0bd48e0007009f7a2e945e606f25b8f8f59bb2/packages/hoppscotch-app/helpers/curl/curlparser.ts#L30) so that It handles the case where **&** is presesnt (example name=11&logistics_id=4&port_id=3). Since the [rawData](https://github.com/hoppscotch/hoppscotch/blob/2d0bd48e0007009f7a2e945e606f25b8f8f59bb2/packages/hoppscotch-app/helpers/curl/curlparser.ts#L48) is derived from [parser](https://github.com/hoppscotch/hoppscotch/blob/2d0bd48e0007009f7a2e945e606f25b8f8f59bb2/packages/hoppscotch-app/helpers/curl/curlparser.ts#L31),the only way to patch this is to modify the preprocess function
Author
Owner

@kyteinsky commented on GitHub (Jun 17, 2022):

umm, the pre-processor is innocent here. Once you comment out the pairs function or make it return null or something falsy, and remove the else if block, you'll see this command would work flawlessly.

<!-- gh-comment-id:1158617071 --> @kyteinsky commented on GitHub (Jun 17, 2022): umm, the pre-processor is innocent here. Once you comment out the pairs function or make it return null or something falsy, and remove the else if block, you'll see this command would work flawlessly.
Author
Owner

@kyteinsky commented on GitHub (Jun 21, 2022):

@John-Weak Still working on this one?

<!-- gh-comment-id:1161244424 --> @kyteinsky commented on GitHub (Jun 21, 2022): @John-Weak Still working on this one?
Author
Owner

@John-Weak commented on GitHub (Jun 21, 2022):

@John-Weak Still working on this one?

Yes,was busy the past few days.
Would look into this today

<!-- gh-comment-id:1161245805 --> @John-Weak commented on GitHub (Jun 21, 2022): > @John-Weak Still working on this one? Yes,was busy the past few days. Would look into this today
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#820
No description provided.