[wp-trac] [WordPress Trac] #40838: REST API: Inconsistent parameter type handling in `set_param()`

WordPress Trac noreply at wordpress.org
Mon May 22 16:24:38 UTC 2017


#40838: REST API: Inconsistent parameter type handling in `set_param()`
--------------------------+------------------------------------------
 Reporter:  jnylen0       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Future Release
Component:  REST API      |    Version:  4.4
 Severity:  minor         |   Keywords:  needs-patch needs-unit-tests
  Focuses:  rest-api      |
--------------------------+------------------------------------------
 Calling `set_param()` on a REST API `WP_REST_Request` object may lead to
 unexpected results.  As of #40344, calling `get_param()` after
 `set_param()` should always work correctly, but the following situation
 could be improved further:

 1. A JSON request comes in with a parameter set in the query string (for
 example, `?key=value`).
 2. `set_param( 'key', 'new_value' )` is called on this request object.
 Since `JSON` is first in `get_parameter_order()`, the request will now
 contain the following parameters:

 - `get_json_params()`: `array( 'key' => 'new_value' )`
 - `get_query_params()`: `array( 'key' => 'value' )`

 Instead, I would expect that `set_param()` loops through the parameter
 order, first checking if the given parameter exists in any parameter type,
 and updating it if so.  Otherwise, it should set the parameter using the
 first parameter type as a last resort.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/40838>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list