fix: use --data-urlencode for form-urlencoded curl snippets#315
Open
fix: use --data-urlencode for form-urlencoded curl snippets#315
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🧰 Changes
Curl snippets for
application/x-www-form-urlencodedendpoints were using--datainstead 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-urlencodefor form-urlencoded params. It behaves identically to--datawhen there's nothing to encode, so no downside. Note that the form data values are never pre-encoded though, sinceoas-to-harjust callsString()on them.This only affects the code snippet shown to developers, the "Try It" executor uses
fetch-harwithURLSearchParamswhich already encodes correctly.🧬 QA & Testing
Find an endpoint with
application/x-www-form-urlencodedcontent type, check that the curl snippet uses--data-urlencodeinstead of--dataCorrect Example
{ "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
{ "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" }