php-http / message

HTTP Message related tools
http://php-http.org
MIT License
1.3k stars 42 forks source link

Force proper arg separator to avoid composing broken URLs #98

Closed OndraM closed 6 years ago

OndraM commented 6 years ago
Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets -
Documentation -
License MIT

What's in this PR?

Make sure http_build_query() uses & as argument separator when assemble query params in URL.

Why?

By default, http_build_query() uses arg_separator.output from php.ini. But this may be set to anything (most often & because of some legacy apps), which will then silently break URLs assembled by the plugin.

For example Guzzle does this as well by default when assembling query strings.

Without the fix this also obviously breaks unit tests when run on our system:

----  broken examples

        Http/Message/Authentication/QueryParam
  29  ! authenticates a request
        method call:
          - withQuery("param1=value1&param2%5B0%5D=value2&userna"...)
        on Double\UriInterface\P34 was not expected, expected calls were:
          - getQuery()
          - withQuery(exact("param1=value1&param2%5B0%5D=value2&username=usern"...))

Checklist