Changes between Initial Version and Version 1 of Ticket #64926, comment 15
- Timestamp:
- 03/27/2026 05:42:29 AM (3 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #64926, comment 15
initial v1 1 1 Subject: Update on #64926 - GitHub PR submitted 2 3 2 Hi @westonruter @zieladam, 4 3 … … 12 11 DX & Consistency: JSON.stringify() is the standard lossless path for structured data in JS. Since REST API already supports this via parse_json_params() for POST bodies, GET requests should ideally mirror this behavior to provide a consistent developer experience. 13 12 14 2. PR Philosophy 13 2. PR Philosophy & Implementation 15 14 The PR introduces JSON Coercion at the entry point of both rest_validate_value_from_schema() and rest_sanitize_value_from_schema(): 16 15 17 Validation : We decode the string early so it can pass the is_object or is_array checks. This prevents the rest_invalid_type (400) error that currently blocks these requests.16 Validation & Sanitization: We decode the string early so it can pass the is_object or is_array checks, preventing the rest_invalid_type (400) error and ensuring the controller receives the correct PHP structured type. 18 17 19 Sa nitization: We perform the same decoding to ensure the data is returned as a proper PHP structured type to the controller callback.18 Safety & Side-Effect Prevention: 20 19 21 Safety: It uses json_last_error() to ensure we only touch valid JSON strings, leaving regular strings or malformed data to be handled by existing strict validation.20 Used json_last_error() to ensure only valid JSON is coerced. 22 21 23 GitHub PR: 24 https://github.com/WordPress/wordpress-develop/pull/11371 22 Added a prefix check ({ or [). This is crucial to prevent unintended decoding of numeric strings (e.g., numeric slugs), which previously caused Undefined index errors in some Template Controller tests. 23 24 Maintained compatibility by using 0 === strpos() for PHP 7.x environments. 25 26 The PR is now passing all REST API unit tests and adheres to WP Coding Standards. 27 28 GitHub PR: https://github.com/WordPress/wordpress-develop/pull/11371