[wp-trac] [WordPress Trac] #57048: Handle trailing slashes in rest_preload_api_request

WordPress Trac noreply at wordpress.org
Thu Jun 27 20:55:48 UTC 2024


#57048: Handle trailing slashes in rest_preload_api_request
-------------------------------------------------+-------------------------
 Reporter:  spacedmonkey                         |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Future
                                                 |  Release
Component:  REST API                             |     Version:  4.7
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests has-        |     Focuses:  rest-api
  testing-info                                   |
-------------------------------------------------+-------------------------
Changes (by antonvlasenko):

 * keywords:  has-patch has-unit-tests => has-patch has-unit-tests has-
     testing-info


Comment:

 The [https://github.com/WordPress/wordpress-develop/pull/6927 proposed PR]
 updates the `rest_preload_api_request` function to remove trailing slashes
 from path parth of the request when preloading data for a specified REST
 API path.

 **Before patch:**
 Preloading `/wp/v2/types//?media//` would return an array with preloaded
 data keyed as `/wp/v2/types//?media`. Only slashes at the end of the path
 were removed.

 **After patch:**
 The path would be `/wp/v2/types?media`.

 **Steps to test this PR:**
 1. Login to the admin panel.
 2. Edit an existing post or create a new one and then click `Edit`.
 3. Open the dev tools, inspect the source code of the page. You should see
 a call to the wp.apiFetch.createPreloadingMiddleware function and the
 preloaded data passed as an argument of that function. Typical preloaded
 requests typically are:
    - `/wp/v2/types?context=view`
    - `/wp/v2/taxonomies?context=view`
    - `/wp/v2/blocks?context=edit&per_page=-1`
    - `/wp/v2/posts/<post-ID>?context=edit`
    - `/wp/v2/types/post?context=edit`
    - `/wp/v2/settings`

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


More information about the wp-trac mailing list