[wp-trac] [WordPress Trac] #42382: REST API: Handle api-request query parameters with plain permalinks

WordPress Trac noreply at wordpress.org
Mon Oct 30 19:48:26 UTC 2017


#42382: REST API: Handle api-request query parameters with plain permalinks
--------------------------+-----------------------------
 Reporter:  aduth         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:  javascript    |
--------------------------+-----------------------------
 Related: #40919
 See: https://github.com/WordPress/gutenberg/issues/3215

 When a site is configured to use plain permalinks, passing an `endpoint`
 or `path` argument containing query parameters prefixed by `?` will fail:

 Example:

 {{{
 wp.apiRequest( {
         namespace: '/wp/v2/',
         endpoint: '/posts?orderby=title'
 } )
 }}}

 This is because we perform a simple concatenation on the API root which in
 the case of plain permalinks results in a URL like:

 `/index.php?rest_route=/wp/v2/posts?orderby=title`

 (Note the two `?`)

 Attached is a patch which resolves this issue by checking whether the API
 root already contains `?` and, if so, converting the `path` of the
 endpoint request to replace `?` with `&`.

 QUnit tests have been updated accordingly.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/42382>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list