Opened 8 years ago
Closed 7 years ago
#42382 closed defect (bug) (fixed)
REST API: Handle api-request query parameters with plain permalinks
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 5.0 | Priority: | normal |
| Severity: | normal | Version: | 4.9 |
| Component: | REST API | Keywords: | commit has-unit-tests |
| Focuses: | javascript | Cc: |
Description
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.
Attachments (1)
Change History (11)
#4
@
8 years ago
Sample workaround fix for plugins encountering this bug: https://github.com/WordPress/gutenberg/pull/4877
#5
@
8 years ago
Alternatively, since it's a common use-case, maybe apiRequest could accept a query object, which is normalized internally. Doesn't help existing usage though.
#7
@
8 years ago
- Keywords commit has-unit-tests added; needs-testing removed
Verified this works as expected, marking for commit.
@adamsilverstein still want to pick this up? Handling the edge cases of permalinks is a frustrating game of whack-a-mole.