Opened 2 weeks ago
Closed 5 days ago
#64666 closed defect (bug) (fixed)
REST API: Prevent fatal when font settings params are non-string in font faces and font families endpoints
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | trunk |
| Component: | REST API | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
The endpoints for creating and updating fonts currently expect stringified JSON for the settings parameters when sent via multipart/form-data.
However, when nested form fields (array/object style) are passed instead of a flat JSON string, the request handling reaches the JSON decoding stage with a non-string value. This triggers a Fatal TypeError rather than returning a standard REST validation error.
Affected Endpoints:
font_face_settings on /wp/v2/font-families/<id>/font-faces
font_family_settings on /wp/v2/font-families (Create/Update)
Steps to Reproduce
Run the following curl command (updating the credentials and URL for your local environment). This uses nested form fields for the settings instead of a JSON string:
curl -i -u "<username>:<password>" \ -X POST "https://your-site.local/wp-json/wp/v2/font-families" \ -F "theme_json_version=3" \ -F "font_family_settings[name]=Inter" \ -F "font_family_settings[slug]=inter" \ -F "font_family_settings[fontFamily]=Inter, sans-serif"
Expected Behavior
The API should not trigger a fatal error. It should return a WP_Error object with:
Code: rest_invalid_param
Status: 400 Bad Request
Message: A clear explanation that the settings parameter must be a valid JSON string.
Actual Behavior
A Fatal TypeError occurs during the JSON decoding process because the code receives an array/object where it strictly expects a string.
Change History (3)
This ticket was mentioned in PR #10966 on WordPress/wordpress-develop by @deepaklalwani.
2 weeks ago
#1
- Keywords has-patch has-unit-tests added
Trac ticket: https://core.trac.wordpress.org/ticket/64666
## Use of AI Tools
Used Github Copilot for unit test cases which is updated and reviewed by me.