[wp-trac] [WordPress Trac] #61061: PHP Warning with invalid JSON input

WordPress Trac noreply at wordpress.org
Thu Mar 20 14:03:17 UTC 2025


#61061: PHP Warning with invalid JSON input
-------------------------------------------------+-------------------------
 Reporter:  dd32                                 |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  low                                  |   Milestone:  6.8
Component:  REST API                             |     Version:  trunk
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests has-        |     Focuses:  rest-api
  testing-info                                   |
-------------------------------------------------+-------------------------
Changes (by SirLouen):

 * keywords:  has-patch has-unit-tests needs-testing has-testing-info =>
     has-patch has-unit-tests has-testing-info


Comment:

 == Combined Bug and Test Reproduction Report
 === Description
 This report validates that the patch works as expected.

 Patch tested: https://github.com/WordPress/wordpress-
 develop/pull/7961.diff

 === Environment
 - WordPress: 6.8-beta3-60042-src
 - PHP: 8.2.28
 - Server: nginx/1.27.4
 - Database: mysqli (Server: 8.4.4 / Client: mysqlnd 8.2.28)
 - Browser: Chrome 134.0.0.0
 - OS: Windows 10/11
 - Theme: Twenty Twenty-Five 1.1
 - MU Plugins: None activated
 - Plugins:
   * Test Reports 1.2.0

 ### Steps to Reproduce
 1. Using `wordpress-develop`, executing command
 {{{
 $ curl http://localhost:8889/wp-json/wp/v2/users/1 --data
 '"+response.write(document.domain)+"' -H 'Content-Type: application/json'
 {"code":"rest_cannot_edit","message":"Sorry, you are not allowed to edit
 this user.","data":{"status":401}}
 }}}
 2. 🐞 Returns warning:
 {{{
 Warning:  foreach() argument must be of type array|object, string given in
 /var/www/src/wp-includes/rest-api/class-wp-rest-request.php on line 828
 }}}

 ### Actual Results after the PR 7961 patch
 1.  ✅ No warning after `curl` has been executed

 ### Additional Notes
 - ✅ Unit tests passing
 - Two unit tests are passing both previously and now, so we can assume
 that further checks are being implemented
 - 🟠 Some tests could be unified into one single test. More info in the
 PR.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/61061#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list