fix: normalize the trailing slash on an inserted site API namespace - #595
Open
dcalhoun wants to merge 1 commit into
Open
Conversation
XCFramework BuildThis PR's XCFramework is available for testing. Add the following to your .package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/595")Built from 499a649 |
dcalhoun
force-pushed
the
fix/normalize-site-api-namespace-slash
branch
from
August 21, 2026 13:18
e5c18e4 to
dc79b90
Compare
`apiPathModifierMiddleware` inserted `siteApiNamespace[0]` verbatim, so a namespace configured without a trailing slash ran into the following segment: `/wp/v2/sites/123` + `posts` produced `/wp/v2/sites/123posts`. Both forms are supported input — `WordPressRESTURL` and `RestUrlBuilder` normalize them identically for native-issued requests, with tests pinning the unslashed case. This middleware was the one consumer not applying that rule. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ULMqNwTEWty4MeNrr94MuF
dcalhoun
force-pushed
the
fix/normalize-site-api-namespace-slash
branch
from
August 21, 2026 13:23
dc79b90 to
499a649
Compare
dcalhoun
marked this pull request as ready for review
August 21, 2026 20:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Normalizes the trailing slash when
apiPathModifierMiddlewareinserts the site API namespace into a request path.Why?
A namespace configured without a trailing slash runs into the following path segment, producing a malformed URL:
/wp/v2/sites/123+postsbecomes/wp/v2/sites/123posts, and the request 404s.Both forms are supported input.
WordPressRESTURL(iOS) andRestUrlBuilder(Android) normalize them identically for native-issued requests, with tests pinning the unslashed case. This middleware was the one consumer not applying that rule.No in-repo host currently emits the unslashed form, but
setSiteApiNamespaceis public API, so a host app can pass either.How?
Strips trailing slashes from the namespace and appends exactly one before inserting it, matching
RestUrlBuilder'strimEnd('/') + "/".Testing Instructions
Covered by automated tests. Verified that the new test fails without the fix, and that it is the only failure.
Accessibility Testing Instructions
Not applicable — no user interface changes.