Skip to content

tool_getparam: preserve field names for empty URL-encoded files - #23577

Closed
derekxmartin wants to merge 2 commits into
curl:masterfrom
derekxmartin:fix-empty-urlencoded-fields
Closed

derekxmartin wants to merge 2 commits into
curl:masterfrom
derekxmartin:fix-empty-urlencoded-fields

Conversation

@derekxmartin

Copy link
Copy Markdown
Contributor

Empty file input is normalized to an empty string in data_urlencode(), but skips the encoding path that adds the field name and equals sign.

Run the size check separately after normalization so empty input reaches that path while retaining oversized-input rejection.

Add regression tests for named empty file and stdin inputs in POST bodies and URL queries, alongside literal empty values and surrounding fields.

Validated on Windows/MSVC: regression tests fail before the fix and pass afterward; existing tests, the 15-case request matrix, allocation-failure tests and style checks pass. Full-suite, sanitizer and other-platform testing were not performed.

AI assistance was used in the investigation and patch preparation.

Empty file input is normalized to an empty string in data_urlencode(),
but skips the encoding path that adds the field name and equals sign.

Run the size check separately after normalization so empty input reaches
that path while retaining oversized-input rejection.

Add regression tests for named empty file and stdin inputs in POST bodies
and URL queries, alongside literal empty values and surrounding fields.

AI assistance was used in the investigation and patch preparation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow control-flow fix preserves existing safeguards, and the regression tests cover both affected options with no unresolved issues identified.

No open issues 🎉

What changed in this PR

This PR fixes curl’s URL-encoding option handling so empty file and stdin inputs retain their field names and equals signs.

Changes:

  • Lets normalized empty input reach the encoding path while preserving oversized-input rejection.
  • Adds POST-body and URL-query regressions covering empty files, stdin, literal values, and surrounding fields.
  • Registers both regression tests.
File Description
tests/​data/​test2141 Tests named empty inputs in URL queries.
tests/​data/​test2140 Tests named empty inputs in URL-encoded POST bodies.
tests/​data/​Makefile.am Registers both new tests.
src/​tool_getparam.c Separates size validation from empty-input normalization.

Review effort: Balanced

Comment thread tests/data/Makefile.am Outdated
test2118 \
test2119 \
test2140 \
test2141 \

This comment was marked as duplicate.

@vszakats vszakats left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we integrate any necessary regression tests into an existing
test case, or drop? It seems to me disproportionate to add and
run two new tests millions of time for a one-liner patch fixing
a rare corner case.

@bagder

bagder commented Oct 23, 2026

Copy link
Copy Markdown
Member

I don't think testing this should be dropped, but it could certainly be integrated into an existing test

Extend tests 1015 and 1624 with named empty file and stdin fields,
literal empty values, and surrounding fields. Preserve the existing
inputs and the second GET after --next.

Remove the standalone tests and their registrations.

AI assistance was used in the investigation and patch preparation.
@bagder bagder closed this in 41efc22 Oct 23, 2026
@bagder

bagder commented Oct 23, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants