Skip to content

fix: normalize the trailing slash on an inserted site API namespace - #595

Open
dcalhoun wants to merge 1 commit into
fix/register-core-media-upload-middlewarefrom
fix/normalize-site-api-namespace-slash
Open

fix: normalize the trailing slash on an inserted site API namespace#595
dcalhoun wants to merge 1 commit into
fix/register-core-media-upload-middlewarefrom
fix/normalize-site-api-namespace-slash

Conversation

@dcalhoun

Copy link
Copy Markdown
Member

What?

Normalizes the trailing slash when apiPathModifierMiddleware inserts 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 + posts becomes /wp/v2/sites/123posts, and the request 404s.

Both forms are supported input. WordPressRESTURL (iOS) and RestUrlBuilder (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 setSiteApiNamespace is 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's trimEnd('/') + "/".

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.

@github-actions github-actions Bot added the [Type] Bug An existing feature does not function as intended label Aug 21, 2026
@wpmobilebot

wpmobilebot commented Aug 21, 2026

Copy link
Copy Markdown

XCFramework Build

This PR's XCFramework is available for testing. Add the following to your Package.swift:

.package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/595")

Built from 499a649

@dcalhoun
dcalhoun force-pushed the fix/normalize-site-api-namespace-slash branch from e5c18e4 to dc79b90 Compare August 21, 2026 13:18
`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
dcalhoun force-pushed the fix/normalize-site-api-namespace-slash branch from dc79b90 to 499a649 Compare August 21, 2026 13:23
@dcalhoun
dcalhoun marked this pull request as ready for review August 21, 2026 20:06
@dcalhoun
dcalhoun requested a review from crazytonyli August 21, 2026 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants