Skip to content

fix: allow routes to contain [ and ] via the [x+5b] and [x+5d] escapes - #16569

Merged
Rich-Harris merged 1 commit into
sveltejs:version-3from
Nic-Polumeyv:fix-route-id-bracket-escapes
Jul 30, 2026
Merged

fix: allow routes to contain [ and ] via the [x+5b] and [x+5d] escapes#16569
Rich-Harris merged 1 commit into
sveltejs:version-3from
Nic-Polumeyv:fix-route-id-bracket-escapes

Conversation

@Nic-Polumeyv

Copy link
Copy Markdown
Contributor

The [ and ] escapes prescribed in documentation/docs/30-advanced/10-advanced-routing.md have never worked: a route directory named [x+5b] fails the build with Invalid regular expression: /^/\\[/?$/: Unterminated character class, and [x+5d] compiles to a pattern that cannot match /]. Introduced with the escape syntax itself in #7644.

escape() escapes [ and ] first to protect the %2[Ff] and %3[Ff] classes the URL substitutions emit, then its final pass re-escapes those backslashes because \\ is in its character class. Regex escaping now runs before the substitutions rather than around them.

parse_route_id output is byte-identical to version-3 for every printable ASCII character and 23 mixed route ids; only [x+5b] and [x+5d] change.

@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 6031e0c:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/6031e0c2ab590c8329bbf056f4d2f0382613bc00

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/16569

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6031e0c

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

@Nic-Polumeyv

Copy link
Copy Markdown
Contributor Author

#16570 fixes the other half of this: resolve() returns escape sequences verbatim, so a pathname built from an escaped route id doesn't match the route. Independent changes, but with both, all 94 printable ASCII escape sequences resolve to a pathname their own pattern matches.

@Rich-Harris
Rich-Harris merged commit 089628b into sveltejs:version-3 Jul 30, 2026
21 of 22 checks passed
@Nic-Polumeyv
Nic-Polumeyv deleted the fix-route-id-bracket-escapes branch July 30, 2026 22:53
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