Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpClient] Query parameters with plus sign ("+") are not quoted anymore #49579

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pl-github opened this issue Mar 2, 2023 · 2 comments
Closed

Comments

@pl-github
Copy link
Contributor

Symfony version(s) affected

5.4.21,6.2.7

Description

In a query part of an URL the plus sign ("+") is a placeholder for a space, so it has to be encoded with "%2B".

In the commit that is fixing the issue which is included in versions 5.4.21 and 6.2.7 the bug has been introduced.

The merge request refers to this stackoverflow thread which describes this as "special meaning".

How to reproduce

HttpClient::create()->request('GET', 'your-url', [
    'query' => [
        'dateTime' => '2022-11-24T18:00:00+01:00'
    ]
]);

Possible Solution

Remove the special processing for unquoting + signs in the query parts.

Additional Context

PHP provides (hopefully) standard compliant functions like urlencode() / rawurlencode() / http_build_query() and they are used here in the code, but the results are modified afterwards.

Maybe it is better to fix such fundamental things directly in PHP and not in a user space library.

The current code of HttpClientTrait.php is very complicated, so I am afraid of opening a merge request. Maybe it is useful to rethink the code (for 6.3 or 6.4), where to use urlencode() and where rawurlencode() and if it is possible to more rely on plain PHP to reduce complexity.

@nicolas-grekas
Copy link
Member

Thanks for the report, my bad for introducing he issue. As a work around, you can encode the query string in the URL yourself.

nicolas-grekas added a commit that referenced this issue Mar 2, 2023
This PR was merged into the 5.4 branch.

Discussion
----------

[HttpClient] Fix encoding "+" in URLs

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #49579
| License       | MIT
| Doc PR        | -

My bad.

Commits
-------

e79eebb [HttpClient] Fix encoding "+" in URLs
@pl-github
Copy link
Contributor Author

Thanks for your fast response.

I skip that specific version of symfony/http-client, so I get 6.2.8 automatically.

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

No branches or pull requests

3 participants