Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#46222 closed defect (bug) (invalid)

Wrong Header Links in REST API

Reported by: flyer29's profile Flyer29 Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: rest-api Cc:

Description

When consuming a link in the REST API leading to a collection and when using a parameter which can have multiple values, the header links for rel="next" etc... are all wrong and can not be consumed to load the next page.

As a really simple example: When calling http://localhost:8080/wp-json/wp/v2/posts?status=publish, the header link of the response contains Link: <http://localhost:8080/wp-json/wp/v2/posts?status%5B0%5D=publish&page=2>; rel="next". This should be http://localhost:8080/wp-json/wp/v2/posts?status=publish&page=2

In this case, in WP_REST_Posts_Controller, the function get_items calculates a $base to be used later in the header using add_query_arg and $request_params. The values of the corresponding key can be arrays (like for status), and should be imploded with "," before being added with add_query_arg.

This bug occurs not only for the posts controller, but for all controllers returning a collection and being able to accept multiple values separated with a "," for a parameter.

Change History (3)

#1 follow-up: @TimothyBlynJacobs
6 years ago

  • Focuses rest-api added
  • Keywords reporter-feedback added

Welcome to trac @Flyer29!

In what way are the links invalid?

That is the url encoded version of ?status[]=publish which is valid syntax.

#2 in reply to: ↑ 1 @Flyer29
6 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Replying to TimothyBlynJacobs:
Hi Timothy,

you are really quick and even more right. This is actually the urlencoded version of status[0]=publish. Knowing this I can now consume the header.

I'm closing the ticket

#3 @ocean90
6 years ago

  • Keywords reporter-feedback removed
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.