[wp-trac] [WordPress Trac] #38873: REST API doesn't match with trailing slash when not using rewrites

WordPress Trac noreply at wordpress.org
Sun Nov 20 00:40:09 UTC 2016


#38873: REST API doesn't match with trailing slash when not using rewrites
--------------------------+------------------
 Reporter:  joehoyle      |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  4.7
Component:  REST API      |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------

Old description:

> Current, a request to the API with rewrite rules enabled doesn't
> differenentiate URLs with trailing slashes just as `http://localhost:8080
> /wp-json/wp/v2/` vs `http://localhost:8080/wp-json/wp/v2`, this seems to
> be a property to WP_Rewrite / class WP to split off the trailing slash
> always.
>
> However, when making requests do
> `http://localhost:8080/?rest_route=/wp/v2/` the trailing slash is not
> stripped, as it doesn't go through the same transformation in `class WP`.
> I think it's safe to always untrailingslash the requested URL in the REST
> API, for matching purposes.

New description:

 Current, a request to the API with rewrite rules enabled doesn't
 differentiate URLs with trailing slashes just as `http://localhost:8080
 /wp-json/wp/v2/` vs `http://localhost:8080/wp-json/wp/v2`, this seems to
 be a property to WP_Rewrite / class WP to split off the trailing slash
 always.

 However, when making requests do
 `http://localhost:8080/?rest_route=/wp/v2/` the trailing slash is not
 stripped, as it doesn't go through the same transformation in `class WP`.
 I think it's safe to always untrailingslash the requested URL in the REST
 API, for matching purposes.

--

Comment (by jnylen0):

 Similarly, the [https://wordpress.org/plugins/rest-api-console/ official
 API console] is broken on my site due to a duplicated slash in between the
 REST prefix and the namespace (`wp-json//wp/v2/posts`):

   [[Image(https://nylen.io/rest-api-console-double-slash.png, 428px)]]

 Other cases:

 1. `//wp-json/wp/v2/posts`: works.
 2. `//wp-json/wp//v2/posts`: does not work.  (Debatable whether it should,
 as `wp/v2` is a valid namespace but `wp//v2` is not.)
 3. `//wp-json/wp/v2//posts`: does not work.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38873#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list