Skip to content

fix: resolve_route prevent dropping a trailing slash of id - #14294

Merged
Rich-Harris merged 1 commit into
sveltejs:mainfrom
yuki0418:fix-resolve-route-traling-slash
Aug 30, 2025
Merged

Rich-Harris merged 1 commit into
sveltejs:mainfrom
yuki0418:fix-resolve-route-traling-slash

Conversation

@yuki0418

@yuki0418 yuki0418 commented Aug 22, 2025 •

Copy link
Copy Markdown
Contributor

Issue #14047

Previous PR was #14065, but it was actually just support a trailing slash for type Pathname, not solving the issue.
Apologize about that I misunderstood the issue.

Problem was resolve() from @app/paths drops trailing slash (technically resolve_route() in resolve() does).
For example resolve('/hoge/huga/') returns string of /hoge/huga

Change to keep the trailing slash if id has the trailing slash.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot

changeset-bot Bot commented Aug 22, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 18a1a60

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot

Copy link
Copy Markdown

@@ -240,6 +240,8 @@ const basic_param_pattern = /\[(\[)?(\.\.\.)?(\w+?)(?:=(\w+))?\]\]?/g;
*/
export function resolve_route(id, params) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I handle the trailing slash in resolve() function instead of inside of this function?

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you

@Rich-Harris
Rich-Harris merged commit fb0f5dd into sveltejs:main Aug 30, 2025
@github-actions github-actions Bot mentioned this pull request Aug 30, 2025
Copilot AI pushed a commit to Stadly/kit that referenced this pull request Mar 6, 2026
teemingc added a commit that referenced this pull request Nov 18, 2026
…17808)

Fixes #17805

Since [#15458](#15458), `resolve()`
accepts route IDs followed by a query string or fragment. That type-only
change assumed the runtime already passed suffixes through correctly,
but `resolve_route` treated the entire input as route segments. A final
`(group)` therefore stopped matching the group predicate and remained in
the destination, producing a 404. Other suffix contents could also
undergo segment filtering, parameter replacement or escape expansion.

Separate the suffix at the first literal `?` or `#` in the shared
resolver, resolve only the route portion, and append the suffix
unchanged. Move the existing missing-params guard and parameter
defaulting there as well, so brackets inside query strings or fragments
do not trigger route-parameter diagnostics. Diagnostics still retain the
original input ID.

This preserves the group-free segment contract used by route parsing and
type generation from
[#14050](#14050), and the
single-pass parameter/escape expansion from
[#16570](#16570). Explicit
trailing-slash preservation from
[#14294](#14294) now inspects only
the route portion, with normalized roots retaining a single slash.
Widening the group regex instead would discard the suffix along with the
group and leave the other suffix transformations unresolved.

Both client and server resolution use this boundary without changing
base-path, request-relative or hash-router prefixing. Literal pathname
inputs still bypass route-ID processing; build-time callers continue
supplying their parameter objects.

- [Minimal SvelteLab
reproduction](https://www.sveltelab.dev/#code=N4IgzgTgxiBcoBMCWECmUAuB7CBPOoAhgA7EB0AFhgLYA2BIAZkrag1FgHYardhwgAPAEIEWTLmKoABFToA%2BADqdBc2tNqFOAcwC8ikLwNLOijKtSEEJs2cHVUGQtKgVCEMI-0gArhkYAtAAcBtIA9DYYdg5O0pyEDt4AbkioAO7EOFEgLlw83N5pSAgYFLoIqClQqAFFJRQANNJInEgYSIS0AWBQnai6AIyhEcq25jHO8YkGPAAeGN29rKEc3LwY3j19w5FmAKRgSai0PADWbZSWCHuj5mEUV5GCAEZYCLjSCIRO3UcnqOcFsQ0LQsFYAl8nN4KFgjhBjLc7MgktIwBhcKxvMgwMRNLhY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wAKx2-XKdwmAHvNyAXdkOPQwgPb8kGMCSBJDpsch6gM8NyApqoKPykID4yzTwPfs875Xv5vJ6%2B6qPacyJfB-nynzw%2BPTV9tDIj-P3feHr8ClSpGkL-rh-ikdIBgB7h1niAXUE5UBSCjLwKAqRT56y-inAW0lUAqzCFYEgIYAiED8FgUeQQJ4T37vfAwaC8aYMBKPAAzGQAYpDP5fwoegzB18Ai4h8NoFovwtRb1NgYduZB6FTzXiwa8AeNR49zID3YRAAmMhKCZiSEDMfbCo8ABsJDaFKIkdfIhIiyAABZQHyVPA%2BDGqdX5kAzlnIUBMNbVy1mhHihFvRfGwoOCS9FKH8MwdgrxEA8EENkq0Xi15%2BLoMBOJRgtFpB0T8f8ahbQwjXzCW4vixEKjME4KgAAwjbTOsT4l0XSZxc8l4%2BI5PwScT4qBckFKKdoX8yDpBcJ4Z7AkcdoltFaR4nBg4CSBJDJZDyedODsk8mraWQA)

<!--
svelte-triage-bot:feedback-baseline:d243d66890c122c246950c28f26c1dc952615c26
-->

---------

Co-authored-by: svelte-triage-bot <[email protected]>
Co-authored-by: Tee Ming <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants