From 951b1d89db05826e79eae5d5861772c5b0cc54d4 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Thu, 9 Apr 2020 19:30:07 +0000 Subject: [PATCH] REST API: Handle parameter types consistently within set_param(). A request has multiple parameter types, including "query" and "json." Updating a parameter could previously modify a key's value in the wrong parameter type, leading to confusing and self-contradictory response objects. Props mnelson4, TimothyBlynJacobs, vagios, jnylen0. Fixes #40838. Built from https://develop.svn.wordpress.org/trunk@47559 git-svn-id: http://core.svn.wordpress.org/trunk@47334 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../rest-api/class-wp-rest-request.php | 19 +++++++++++++++++-- wp-includes/version.php | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/wp-includes/rest-api/class-wp-rest-request.php b/wp-includes/rest-api/class-wp-rest-request.php index d6146127ed..e3ed8c424a 100644 --- a/wp-includes/rest-api/class-wp-rest-request.php +++ b/wp-includes/rest-api/class-wp-rest-request.php @@ -420,14 +420,29 @@ class WP_REST_Request implements ArrayAccess { /** * Sets a parameter on the request. * + * If the given parameter key exists in any parameter type an update will take place, + * otherwise a new param will be created in the first parameter type (respecting + * get_parameter_order()). + * * @since 4.4.0 * * @param string $key Parameter name. * @param mixed $value Parameter value. */ public function set_param( $key, $value ) { - $order = $this->get_parameter_order(); - $this->params[ $order[0] ][ $key ] = $value; + $order = $this->get_parameter_order(); + $found_key = false; + + foreach ( $order as $type ) { + if ( 'defaults' !== $type && array_key_exists( $key, $this->params[ $type ] ) ) { + $this->params[ $type ][ $key ] = $value; + $found_key = true; + } + } + + if ( ! $found_key ) { + $this->params[ $order[0] ][ $key ] = $value; + } } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 7ce1d8ea20..e41b7a4ac6 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.5-alpha-47558'; +$wp_version = '5.5-alpha-47559'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.