#38306 closed defect (bug) (fixed)
WP_REST_Request->get_params strips numeric keys
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.7 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | REST API | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Right now, a numeric key is getting stripped.
Request Body = {"41150":"API value"}
$request->get_params = [1] => API value
So line 453 in class-wp-rest-request.php:
$params = array_merge( $params, (array) $this->params[ $type ] );
should be:
$params = $params + (array) $this->params[ $type ];
Any chance of getting this into 4.7?
Attachments (1)
Change History (12)
This ticket was mentioned in Slack in #core-restapi by rachelbaker. View the logs.
7 years ago
#3
@
7 years ago
Thanks. I didn't think about that since my test data was flat. Looks like my fix won't cover it then.
#6
@
7 years ago
@joehoyle Saw you milestoned this as 4.7. Are you going to shepherd this ticket before beta?
#7
@
7 years ago
- Owner set to joehoyle
- Status changed from new to assigned
@rachelbaker yes! Set myself as owner.
#8
@
7 years ago
While discussing this ticket with @joehoyle he pointed out that @sswells was using a numeric string in her array key, and that would result in the +
operator recursively combining the arrays: https://3v4l.org/qdhJC
#9
@
7 years ago
- Keywords has-patch has-unit-tests added
array_merge
and the + operator are both issues, as even the +
will make numeric keys integers after it's done. It seems the easiest and best way is to manually implement a foreach. Added unit test also.
@sswells We cannot use the combine operator for the associative arrays because it does not merge arrays recursively. See https://3v4l.org/ultWd
It looks like the only way to patch this correctly needs to allow numeric array keys to be retained without being re-indexed, while still merging recursive data as well.