Skip to content

fix: use --data-urlencode for form-urlencoded curl snippets#315

Open
HugoHSun wants to merge 1 commit intomainfrom
hugo/cx-2935-ngc-curl-example-uses-data-instead-of-data-urlencode-for
Open

fix: use --data-urlencode for form-urlencoded curl snippets#315
HugoHSun wants to merge 1 commit intomainfrom
hugo/cx-2935-ngc-curl-example-uses-data-instead-of-data-urlencode-for

Conversation

@HugoHSun
Copy link

@HugoHSun HugoHSun commented Feb 17, 2026

🚥 Resolves CX-2935

🧰 Changes

Curl snippets for application/x-www-form-urlencoded endpoints were using --data instead of --data-urlencode. This meant values with special characters (spaces, ampersands, etc.) would break when copy-paste and execute in a terminal.

The old code only checked if the param name needed encoding and picked the flag based on that, while ignoring the value. The fix: always use --data-urlencode for form-urlencoded params. It behaves identically to --data when there's nothing to encode, so no downside. Note that the form data values are never pre-encoded though, since oas-to-har just calls String() on them.

This only affects the code snippet shown to developers, the "Try It" executor uses fetch-har with URLSearchParams which already encodes correctly.

🧬 QA & Testing

Find an endpoint with application/x-www-form-urlencoded content type, check that the curl snippet uses --data-urlencode instead of --data

Correct Example

curl --request POST \
  --url https://httpbin.org/anything \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data-urlencode 'foo=bar' \
  --data-urlencode 'query=hello world' \
  --data-urlencode 'filter=status=active&type=user'
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "filter": "status=active&type=user", 
    "foo": "bar", 
    "query": "hello world"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "62", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/8.7.1", 
    "X-Amzn-Trace-Id": "Root=1-69942c21-2119bf28086765883dfaa673"
  }, 
  "json": null, 
  "method": "POST", 
  "origin": "1.1.1.1", 
  "url": "https://httpbin.org/anything"
}

Incorrect Example

curl --request POST \
  --url https://httpbin.org/anything \
  --header 'content-type: application/x-www-form-urlencoded' \
  --data 'foo=bar' \
  --data 'query=hello world' \
  --data 'filter=status=active&type=user'
{
  "args": {}, 
  "data": "", 
  "files": {}, 
  "form": {
    "filter": "status=active", 
    "foo": "bar", 
    "query": "hello world", 
    "type": "user"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Content-Length": "56", 
    "Content-Type": "application/x-www-form-urlencoded", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/8.7.1", 
    "X-Amzn-Trace-Id": "Root=1-69942d09-4ad6930b09907b011e840bec"
  }, 
  "json": null, 
  "method": "POST", 
  "origin": "1.1.1.1", 
  "url": "https://httpbin.org/anything"
}

@HugoHSun HugoHSun requested a review from erunion as a code owner February 17, 2026 08:56
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

Successfully merging this pull request may close these issues.

1 participant

Comments