[wp-trac] [WordPress Trac] #63576: API Requests sometimes lose body
WordPress Trac
noreply at wordpress.org
Mon Jun 16 19:25:13 UTC 2025
#63576: API Requests sometimes lose body
--------------------------+------------------------------
Reporter: granthony | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: HTTP API | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+------------------------------
Changes (by sabernhardt):
* version: trunk =>
Old description:
> In limited circumstances, HTTP requests made using wp-
> includes/Requests/src/Requests.php will incorrectly return an empty
> string as the response body, even though the request executed and
> returned a value in the response.
>
> This happens when the returned value is PHP-falsey (for example, the
> string "0") - or in other words, when empty($value) evaluates to true in
> PHP.
>
> I've encountered this issue in production, so the diff we went with is
> attached.
New description:
In limited circumstances, HTTP requests made using `wp-
includes/Requests/src/Requests.php` will incorrectly return an empty
string as the response body, even though the request executed and returned
a value in the response.
This happens when the returned value is PHP-falsey (for example, the
string `"0"`) - or in other words, when `empty($value)` evaluates to true
in PHP.
I've encountered this issue in production, so the diff we went with is
attached.
--
Comment:
(See
[https://github.com/WordPress/Requests/blob/8382ce930c085a88c302baed9617f45008e5ef48/src/Requests.php#L742
line 742] on the GitHub repository if you want to create a pull request.)
The `substr()` function should always
[https://www.php.net/manual/en/function.substr.php return a string]. I
think simply checking for an empty string would suffice:
`if ($body !== '')`
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63576#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list