Skip to content

Explicitly state the argument separator when encoding POST data - #100

Open
coling wants to merge 1 commit into
joomla-framework:4.x-devfrom
coling:http-build-query-explicit
Open

coling wants to merge 1 commit into
joomla-framework:4.x-devfrom
coling:http-build-query-explicit

Conversation

@coling

@coling coling commented Nov 23, 2026

Copy link
Copy Markdown

When the PHP arg_separator.output option is not & (e.g. it is set to &), http_build_query() joins the encoded fields with it. An array body passed to the Curl, Socket or Stream transport is then sent as key=value&other=second, and the receiving end sees the fields key and amp;other.

This is easily seen with Google's reCAPTCHA: Joomla 6's Joomla\CMS\Captcha\Google\HttpBridgePostRequestMethod builds its client with Joomla\Http\HttpFactory, so it goes through these transports, and siteverify answers invalid-input-response to every submission because it never receives a response field.

This is the framework counterpart of joomla/joomla-cms#43452, which makes the same change to the CMS's own libraries/src/Http/Transport/* classes. That PR alone does not fix code that uses the framework transports.

Summary of Changes

  • Pass '&' as the separator to http_build_query() in Transport\Curl, Transport\Socket and Transport\Stream.
  • Add TransportTest::testRequestPostIgnoresArgSeparatorOutput, which posts two fields with arg_separator.output set to & through each transport and checks both arrive under their own names.

Testing Instructions

Run the unit tests with the stub server, as CI does:

php -S localhost:8080 -t Tests/stubs &
./vendor/bin/phpunit

Actual result BEFORE applying this Pull Request

The new test fails for all three transports: the stub receives amp;other instead of other.

Expected result AFTER applying this Pull Request

The new test passes for all three transports (full suite: 51 tests OK; phpcs clean).

🤖 Generated with Claude Code

When the PHP arg_separator.output option is not "&" (e.g. it is set to
"&"), http_build_query() joins the encoded fields with it, so an
array body is sent as "key=value&other=second" and the receiving end
sees the fields "key" and "amp;other". This breaks any API called with
array data through the Curl, Socket or Stream transports, for example
Google's reCAPTCHA siteverify, which then answers
"invalid-input-response" because it never receives a "response" field.

Pass "&" to http_build_query() in all three transports, and add a test
that posts two fields with arg_separator.output set to "&".

This is the framework counterpart of joomla/joomla-cms#43452, which makes
the same change to the CMS's own transports.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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