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
Cookies with numeric/integer names cause exception. #845
Comments
On Trac, I had originally proposed casting the array keys to strings, but apparently PHP will just convert them back to integers, so the fix is either to cast the the cookie name to a string when calling the constructor for Cookie() ( Line 82 in 4226129
|
Fixes WordPress#845 so that an exception isn't thrown for legitimate numeric cookie names.
Please back up this statement as I cannot, for the life of me, find where in the specs it allows for an integer name. As far as I can see, the name should always be a string, though a numeric string would be allowed. |
Agreed, the spec doesn't specifically state integer names are allowed.
The trouble is, even if one changes the numeric value to a string (in my example), the error is thrown, because PHP converts numeric array indices to integers (if possible). If I knew which WP plugin was setting such odd cookies, I'd beg them to stop. But it can and does happen, and it's technically permissible, so they might just say, "not a bug, go away..." *Nevermind the unit tests, I think I figured that out, just had to learn some new things in the phpunit docs! |
Summary
As reported in https://core.trac.wordpress.org/ticket/58566 when a cookie with a numeric name is used in a request, an exception is thrown. Though a cookie with a numeric name seems odd to me, it is permitted by the spec, and happens "in the wild".
Given the following code sample
I'd expect the following behaviour
The request to succeed.
Instead this happened
Additional context
To my knowledge, this affects several plugins making async requests in WordPress, including EWWW Image Optimizer and WooCommerce, and also possibly WP core (site health check).
Your environment
Tested against
develop
branch?develop
branch of Requests.The text was updated successfully, but these errors were encountered: