Make WordPress Core

Opened 3 years ago

Closed 6 months ago

Last modified 37 hours ago

#57048 closed defect (bug) (fixed)

Handle trailing slashes in rest_preload_api_request

Reported by: spacedmonkey's profile spacedmonkey Owned by: swissspidy's profile swissspidy
Milestone: 6.8 Priority: normal
Severity: normal Version: 5.0
Component: REST API Keywords: has-patch has-unit-tests has-test-info commit
Focuses: rest-api Cc:

Description

When passing a path to rest_preload_api_request that ends in query string, ensure that the parsed path also is untrailingslashit. Follow up to #51636

Change History (12)

#1 @antonvlasenko
11 months ago

I'm working on a patch for this issue.

This ticket was mentioned in PR #6927 on WordPress/wordpress-develop by @antonvlasenko.


11 months ago
#2

  • Keywords has-patch has-unit-tests added; needs-patch removed

#3 @antonvlasenko
11 months ago

  • Keywords has-testing-info added

The 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 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
Last edited 10 months ago by antonvlasenko (previous) (diff)

#4 follow-up: @spacedmonkey
7 months ago

Me and @swissspidy came across this issue while working web stories together. We patched it in our own code. Here is our version of this function.

I can't remember now how we fixed this issue, but look at the git history.

#5 @swissspidy
7 months ago

  • Milestone changed from Future Release to 6.8

#6 @swissspidy
7 months ago

  • Version changed from 4.7 to 5.0

#7 @swissspidy
7 months ago

  • Owner set to swissspidy
  • Status changed from new to assigned

#8 in reply to: ↑ 4 @antonvlasenko
7 months ago

Replying to spacedmonkey:

Me and @swissspidy came across this issue while working web stories together. We patched it in our own code. Here is our version of this function.

I can't remember now how we fixed this issue, but look at the git history.

Thank you for the hint, @spacedmonkey.
I believe this is the commit that addresses the issue in your version of the function: https://github.com/GoogleForCreators/web-stories-wp/commit/a7f4977f74d24f73c0a72d23501f6a1eb7ac9337#diff-e38e7938d6df1990969cd7d147a8d590b359fa3a96a33802c85aa5723abf0223R188

The proposed solution appears to not only resolve the issue you mentioned, but also correct the key at which preloaded data is stored (within the context of array_reduce()).

Last edited 7 months ago by antonvlasenko (previous) (diff)

#9 @spacedmonkey
6 months ago

  • Keywords commit added

I have approved the PR for this change. Looks good to me. I have marked this ticket as commit. Take it away @swissspidy

#10 @swissspidy
6 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 59457:

REST API: Remove trailing slashes when preloading requests and there is a query string.

Follow-up to [51648], see #51636.

Props antonvlasenko, swissspidy, spacedmonkey.
Fixes #57048.

#12 @wordpressdotorg
37 hours ago

  • Keywords has-test-info added; has-testing-info removed
Note: See TracTickets for help on using tickets.