refactor: extract trailing-slash helpers into url utils - #724
Merged
Merged
Conversation
dcalhoun
added this pull request to stack #726
September 23, 2026 19:10
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/724")Built from 89f9521 |
dcalhoun
force-pushed
the
refactor/url-trailing-slash-helpers
branch
2 times, most recently
from
September 23, 2026 20:17
eb90759 to
0848c88
Compare
dcalhoun
marked this pull request as ready for review
September 24, 2026 10:48
The same trailing-slash rule was written inline in three places, so the three could drift apart as each gained its own edge-case handling. A shared pair of helpers keeps them together. The helpers absorb an absent value, since every caller reads an optional config field and would otherwise repeat the same guard. A wrong type still throws rather than passing through silently. No behavior change. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014V7YC1kW6f5ZFHtMNGcLKs
dcalhoun
force-pushed
the
refactor/url-trailing-slash-helpers
branch
from
September 24, 2026 10:59
0848c88 to
89f9521
Compare
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?
Extract utilities for managing URL trailing slashes.
Why?
Address feedback in #617 (comment). Mitigate bugs from repeated logic.
How?
Add
stripTrailingSlashandensureTrailingSlashURL utilities.Testing Instructions
N/A, no user-facing changes.
Accessibility Testing Instructions
N/A, no user-facing changes.
Screenshots or screencast
N/A, no user-facing changes.
AI-generated details
The same trailing-slash rule was written inline in three places:
configureAjax,siteIndexMiddleware, andapiPathModifierMiddleware. Nothing tied them together, so each could gain its own edge-case handling and drift from the others — for instance if one started trimming leading slashes too.src/utils/url.jsnow exportsstripTrailingSlashandensureTrailingSlash, and the three call sites use them.Every caller reads an optional config field, so the helpers absorb an absent value (
undefined,nullor empty) rather than making each caller guard:stripTrailingSlashreturns an empty string andensureTrailingSlashstays empty rather than becoming a lone/, which would resolve against the page root. A value of/is kept, since that is a meaningful root. Any other non-string still throws, so a wrong type is not quietly passed through.No behavior change.
Testing
src/utils/url.test.jscovers both helpers, including repeated slashes, absent values, and the non-string case.