Make WordPress Core

Opened 4 weeks ago

Closed 3 weeks ago

#63576 closed defect (bug) (reported-upstream)

API Requests sometimes lose body

Reported by: granthony's profile granthony Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: HTTP API Keywords:
Focuses: Cc:

Description (last modified by sabernhardt)

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.

Attachments (1)

wp-request.patch (707 bytes) - added by granthony 4 weeks ago.
Patch for WP::Requests class to handle '0' response body

Download all attachments as: .zip

Change History (4)

@granthony
4 weeks ago

Patch for WP::Requests class to handle '0' response body

#1 @mindctrl
4 weeks ago

I think patches for Requests go in the upstream library here: https://github.com/WordPress/Requests

#2 @sabernhardt
4 weeks ago

  • Description modified (diff)
  • Version trunk deleted

(See line 742 on the GitHub repository if you want to create a pull request.)

The substr() function should always return a string. I think simply checking for an empty string would suffice:
if ($body !== '')

#3 @sabernhardt
3 weeks ago

  • Milestone Awaiting Review deleted
  • Resolution set to reported-upstream
  • Status changed from new to closed

Apparently I was wrong about returning a string (in all versions of PHP), but the pull request is on GitHub for further discussion:
https://github.com/WordPress/Requests/pull/933

Note: See TracTickets for help on using tickets.