Skip to content

Fix parsing urlencoded pairs with empty values. - #6980

Merged
jackkav merged 1 commit into
Kong:developfrom
adamroyle:fix-curl-parse-data-raw
Apr 11, 2024
Merged

Fix parsing urlencoded pairs with empty values.#6980
jackkav merged 1 commit into
Kong:developfrom
adamroyle:fix-curl-parse-data-raw

Conversation

@adamroyle

Copy link
Copy Markdown
Contributor

There is a bug with parsing curl statements with empty values. This fixes the bug and adjusts the tests to expected behavior.

@CLAassistant

CLAassistant commented Jan 11, 2024

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@filfreire
filfreire force-pushed the fix-curl-parse-data-raw branch from c67559f to a28d283 Compare March 27, 2024 15:22
@filfreire

Copy link
Copy Markdown
Contributor

Hi @adamroyle thanks for submitting this! We're eager to help you get this into a merged state.

While I was testing this PR out locally I've found some cases where we will still not properly render urlencoded pairs. Can you provide an example you used for testing this PR?

@adamroyle

Copy link
Copy Markdown
Contributor Author

I'm just using a simple example:

curl 'http://localhost/' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  --data-raw 'param1=&param2=&param3=value'

As an aside, however, I found another issue where Bash-style ANSI-C quoted strings (eg. --data-raw $'....') were not decoded properly. Google Chrome's "Copy as cURL" feature uses them for JSON strings that contain special chars.

eg.

curl 'http://localhost/' \
  -H 'Content-Type: application/json;charset=UTF-8' \
  --data-raw $'{"name":"O\'Reilly"}'

I spent a while trying to get it to work but ran into too many issues (mainly with general shell parsing libraries not implementing Bash-style quotes), and instead built a parser for "Copy as fetch (Node.js)" instead which has been much more reliable.

@jackkav
jackkav force-pushed the fix-curl-parse-data-raw branch from a28d283 to 1bdf78f Compare April 11, 2024 07:01
@jackkav
jackkav merged commit 0a2187f into Kong:develop Apr 11, 2024
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.

5 participants