Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#48266 closed defect (bug) (fixed)

REST API: logic used to filter nested _fields does not account for specifying multiple siblings

Reported by: kadamwhite's profile kadamwhite Owned by: kadamwhite's profile kadamwhite
Milestone: 5.3 Priority: normal
Severity: normal Version: 5.3
Component: REST API Keywords: has-unit-tests has-patch has-dev-note
Focuses: rest-api Cc:


In #42094 we introduced logic to extend the _fields query parameter in order to specify that we wanted only one piece of a deeply nested object. While writing the dev note for this feature I discovered a logical error where our logic failed to account for the case where we specify two sibling properties of the same nested object.

For example, given the response object

        "id": 1,
        "meta": {
                "key1": 1,
                "key2": 2

and the query /wp/v2/posts/1?_fields=meta.key1,meta.key2, only meta.key2 will be included.

We can fix this by adjusting the manner in which rest_filter_response_fields sets the $ref[ $next ] value to account for an existing array at that location.

Attachments (3)

48266.1.diff (1.6 KB) - added by kadamwhite 5 years ago.
48266.2.diff (2.9 KB) - added by kadamwhite 5 years ago.
48266.3.diff (2.9 KB) - added by kadamwhite 5 years ago.
Correct descriptive comment for test

Download all attachments as: .zip

Change History (6)

5 years ago

5 years ago

5 years ago

Correct descriptive comment for test

This ticket was mentioned in Slack in #core-restapi by kadamwhite. View the logs.

5 years ago

#2 @kadamwhite
5 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 46456:

REST API: Fix error in _fields filtering logic where only one of several requested sibling properties would be included.

Props kadamwhite, TimothyBlynJacobs.
Fixes #48266.

Note: See TracTickets for help on using tickets.