Repository navigation
Conversation
…NUL byte. As of PHP 8.6, `parse_str()` throws a `ValueError` when its input contains a NUL byte. Earlier PHP versions stopped reading at the first NUL byte and returned what had been parsed up to that point. `wp_parse_str()` passes its input straight through, so `add_query_arg()`, `remove_query_arg()` and `wp_parse_args()` now throw on PHP 8.6 for input they previously accepted. The input is now cut at the first NUL byte before parsing, which keeps the earlier result on every supported PHP version.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…byte. `WP_REST_Request::parse_body_params()` passes the raw request body to `parse_str()` for PUT, PATCH and DELETE requests. As of PHP 8.6 that throws a `ValueError` when the body contains a NUL byte, where earlier versions stopped reading at that byte. The body is now cut at the first NUL byte before parsing, matching the change to `wp_parse_str()`.
As of PHP 8.6,
parse_str()throws aValueErrorwhen its input contains a NUL byte. Earlier versions stopped reading at the first NUL byte.wp_parse_str()passes its input straight through, soadd_query_arg(),remove_query_arg()andwp_parse_args()now throw on PHP 8.6 for input they used to accept.WP_REST_Request::parse_body_params()has the same problem. It passes the raw body of a PUT, PATCH or DELETE request toparse_str(), so a URL-encoded body containing a NUL byte now ends the request with an uncaughtValueError.WP_REST_Server::dispatch()validates parameters before the permission callback runs, so from reading the code this does not need authentication. I have tested it throughWP_REST_Requestin PHPUnit, not over HTTP.This cuts the string at the first NUL byte before parsing in both places, which keeps the earlier result on every supported PHP version. I picked that because it changes nothing on older PHP. Stripping NUL bytes instead would also work if that is preferred.
Testing
Calling the unmodified trunk functions:
add_query_arg( 'a', 'b', "http://example.org/?x=y\0z" )on trunkhttp://example.org/?x=y&a=bValueErrorhttp://example.org/?x=y&a=bhttp://example.org/?x=y&a=bremove_query_arg()andwp_parse_args()behave the same way.PHPUnit, with the new test cases:
tests/formatting/wpParseStr.phpValueError)tests/formatting/wpParseStr.phptests/functions.phptests/functions/removeQueryArg.phpTests_REST_RequestValueError)Tests_REST_RequestTests_REST_ServerThe new cases pass on trunk below PHP 8.6 because they pin the existing result. PHPCS passes on the changed files.
Trac ticket: https://core.trac.wordpress.org/ticket/66785
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Used for: Finding the issue from the PHP 8.6 upgrade notes, writing the change, the tests and this description, and running the tests. The test results above are automated runs by the tool.