Generated curl is invalid for url encoded data
- Dominant language
- TypeScript
- Stars
- 40k
- Forks
- 2.4k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 61
Description
### Expected Behavior
For REST queries having `Form URL Encoded`, when using the `Copy as Curl` the `--data-urlencode` otherwise it can break the query when we try to execute it.
### Actual Behavior
If I click on the `Send` button in Insomnia and I go into the `Timeline` tab, I can see that my multiline free text :

was encoded:
```sh
query=%0ASELECT+%3Fs+%3Fp+%3Fo%0AWHERE+%7B+%0A++%3Fs+%3Fp+%3Fo+.%0A%7D%0ALIMIT+10
```
But if I use the `Copy as Curl` feature, the generated query looks like this:
```sh
curl --request POST \
--url https://cluster.neptune.amazonaws.com:8182/sparql \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data 'query=
SELECT ?s ?p ?o
WHERE {
?s ?p ?o .
}
LIMIT 10'
```
Then in my command line, if I try to execute the query, I get an error because the change of line characters were not encoded:
```json
{
"detailedMessage": "Malformed query: Encountered \"\" at line 1, column 0.\nWas expecting one of:\n \"base\" ...\n \"prefix\" ...\n \"select\" ...\n \"construct\" ...\n \"describe\" ...\n \"ask\" ...\n ",
"requestId": "285a34e1-8a78-4d97-8285-0c7f26527bef",
"code": "MalformedQueryException"
}
```
If I just modify the `--data` to `--data-urlencode` then the same query works:
```sh
curl --request POST \
--url https://cs-taxonomy.cluster-ck0qdwknsfda.us-west-2.neptune.amazonaws.com:8182/sparql \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'query=
SELECT ?s ?p ?o
WHERE {
?s ?p ?o .
}
LIMIT 10'
```
### Reproduction Steps
1. Create a `POST` query with any hostname
2. Select `Form URL Encoded`
3. Add a parameter `query` and for the value, select from the dropdown `Text (Multi-line)`
4. Paste any multi-line text, for example a Sparql query:
```
SELECT ?s ?p ?o
WHERE {
?s ?p ?o .
}
LIMIT 10
```
5. In the left menu, right click on the name of your request and select `Copy as Curl`
### Is there an existing issue for this?
- [X] I have searched the [issue tracker](https://www.github.com/Kong/insomnia/issues) for this problem.
### Additional Information
When I tried to do the same in Postman, I noticed this feature was properly handled. I would imagine this issue is not only present for EOL characters, some other characters should be encoded, but this is probably the most common issue.
### Insomnia Version
2022.7.5
### What operating system are you using?
macOS
### Operating System Version
macOS Monterey 12.6.2
### Installation method
download from insomnia.rest
### Last Known Working Insomnia version
NA
Contributor guide
Research direction
Start by reproducing the issue through the Form URL Encoded request flow and the Copy as Curl entry point, then compare the generated command with the Timeline encoding. Done means multiline URL-encoded form values produce a curl command that executes successfully without losing line-break or special-character encoding.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100