WordPress.org

Make WordPress Core

Opened 12 days ago

Closed 11 days ago

Last modified 10 days ago

#48266 closed defect (bug) (fixed)

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

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

Description

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 12 days ago.
48266.2.diff (2.9 KB) - added by kadamwhite 12 days ago.
48266.3.diff (2.9 KB) - added by kadamwhite 12 days ago.
Correct descriptive comment for test

Download all attachments as: .zip

Change History (6)

@kadamwhite
12 days ago

@kadamwhite
12 days ago

@kadamwhite
12 days ago

Correct descriptive comment for test

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


12 days ago

#2 @kadamwhite
11 days 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.