[wp-trac] [WordPress Trac] #61061: PHP Warning with invalid JSON input
WordPress Trac
noreply at wordpress.org
Thu Mar 27 06:55:32 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 |
-------------------------------------------------+-------------------------
Comment (by devsahadat):
Thank you for reporting the bug and for providing a solution. I’ve
thoroughly reviewed the issue and tested the proposed patch.
Bug Summary:
The problem occurs when a malformed JSON input (e.g., a string or numeric
value) is sent in a REST API request, causing a PHP warning due to the
foreach() function attempting to iterate over a non-array input.
Solution Evaluation:
The proposed patch effectively skips the sanitization step for scalar
inputs, such as strings or numbers, ensuring that only arrays are
processed with the foreach() function. This solution resolves the PHP
warning as intended.
Test Results:
I have tested the patch by replicating the original issue with the cURL
command and verifying the debug logs. After applying the patch, no
warnings or errors were logged, confirming that the issue has been
resolved.
Additional Insights:
While the patch addresses the specific warning, I suggest further testing
with different types of invalid inputs (e.g., arrays with invalid types)
to ensure robustness. Additionally, it would be good to verify whether
this change affects any existing validation or sanitization rules that may
be in place for specific API endpoints.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61061#comment:25>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list