[wp-trac] [WordPress Trac] #61842: Uncaught TypeError in /wp-json/wp/v2/menu-items REST API POST operation
WordPress Trac
noreply at wordpress.org
Thu Aug 8 10:00:13 UTC 2024
#61842: Uncaught TypeError in /wp-json/wp/v2/menu-items REST API POST operation
--------------------------+-----------------------------
Reporter: mlf20 | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 6.2.2
Severity: normal | Keywords:
Focuses: rest-api |
--------------------------+-----------------------------
Upon creating a fresh instance of WordPress and setting up the REST API a
malformed post request REST API endpoint /wp-json/wp/v2/menu-items results
in an exception in the endpoint.
Arises from an array being given in request when a string is expected.
Would expect a 400 Bad Request for any unexpected types.
=== Command to reproduce
curl -X POST "http://[WORDPRESSDOMAIN]/wp-json/wp/v2/menu-items" -d
'{"title":"fuzzstring","type":"fuzzstring","status":"fuzzstring","parent":0,"attr_title":"fuzzstring","classes":["fuzzstring"],"description":"fuzzstring","menu_order":0,"object":"fuzzstring","object_id":0,"target":"fuzzstring","url":{
"fuzz" : false },"xfn":["fuzzstring"],"menus":0}' -H 'Content-Type:
application/json'
=== Stacktrace
{{{
<b>Fatal error</b>: Uncaught TypeError: ltrim(): Argument #1 ($string)
must be of type string, array given in /var/www/html/wp-
includes/formatting.php:4415
Stack trace:
#0 /var/www/html/wp-includes/formatting.php(4415): ltrim(Array)
#1 /var/www/html/wp-includes/formatting.php(4540): esc_url(Array, NULL,
'db')
#2 /var/www/html/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-
controller.php(856): sanitize_url(Array)
#3 /var/www/html/wp-includes/rest-api/class-wp-rest-request.php(911):
WP_REST_Menu_Items_Controller::{closure}(Array, Object(WP_REST_Request),
'url')
#4 /var/www/html/wp-includes/rest-api/class-wp-rest-server.php(1018):
WP_REST_Request->has_valid_params()
#5 /var/www/html/wp-includes/rest-api/class-wp-rest-server.php(443):
WP_REST_Server->dispatch(Object(WP_REST_Request))
#6 /var/www/html/wp-includes/rest-api.php(410):
WP_REST_Server->serve_request('/wp/v2/menu-ite...')
#7 /var/www/html/wp-includes/class-wp-hook.php(308):
rest_api_loaded(Object(WP))
#8 /var/www/html/wp-includes/class-wp-hook.php(332):
WP_Hook->apply_filters('', Array)
#9 /var/www/html/wp-includes/plugin.php(565): WP_Hook->do_action(Array)
#10 /var/www/html/wp-includes/class-wp.php(399):
do_action_ref_array('parse_request', Array)
#11 /var/www/html/wp-includes/class-wp.php(780): WP->parse_request('')
#12 /var/www/html/wp-includes/functions.php(1334): WP->main('')
#13 /var/www/html/wp-blog-header.php(16): wp()
#14 /var/www/html/index.php(17): require('/var/www/html/w...')
#15 {main}
thrown in <b>/var/www/html/wp-includes/formatting.php</b> on line
<b>4415</b><br />
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/61842>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list