Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated multipart curl doesn't escape characters of form data fields #260

Open
filfreire opened this issue May 10, 2022 · 1 comment
Open

Comments

@filfreire
Copy link
Member

Related with Kong/insomnia#3868

As of now we are not escaping double-quote characters that are in data fields of curl requests. This causes the curl request to fail.

Example generated curl:

curl --request GET \
  --url http://mockbin.org/request/anything \
  --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \
  --form timestamp=2022-05-10T10:04:18.748Z \
  --form field=test \
  --form 'data=<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<test>TEST<test>'

This doesn't seem to be the case for example for Python, where we escape characters we need to, and the request works fine:

import requests

url = "http://mockbin.org/request/anything"

payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"timestamp\"\r\n\r\n2022-05-10T10:07:25.650Z\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"field\"\r\n\r\ntest\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"data\"\r\n\r\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<test>TEST<test>\r\n-----011000010111000001101001--\r\n"
headers = {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'}

response = requests.request("GET", url, data=payload, headers=headers)

print(response.text)

Example postman generated curl:

curl --location --request POST 'https://test.com' \
--form 'timestamp="2021-07-14T01:02:34.567Z"' \
--form 'field="test"' \
--form 'data="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<test>TEST<test>"'
@filfreire
Copy link
Member Author

Another issue we might have, similar to this one, we don't include the content type for each form part.

Example from Kong/insomnia#4334

What httpsnippet exports:

curl --request POST \
  --url http://localhost:8080/upload-file \
  --header 'Content-Type: multipart/form-data; boundary=---011000010111000001101001' \
  --form 'metadata={
	"description": "Some description for my file"
}' \
  --form file=@/Users/user/Documents/file.md

What postman exports:

curl --location --request POST 'localhost:8080/upload-file' \
--form 'metadata="{
  \"description\": \"Some description for my file\"
}";type=application/json' \
--form 'file=@"/Users/[email protected]/Documents/a.diff"'

We are missing the ;type=application/json chunk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant