Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pattern matching for @ encoded routes #6110

Merged
merged 1 commit into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rich-walls-doubt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Fix pattern matching for routes starting with an encoded `@` symbol
9 changes: 5 additions & 4 deletions packages/kit/src/utils/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ export function parse_route_id(id) {
id === ''
? /^\/$/
: new RegExp(
`^${decodeURIComponent(id)
`^${id
.split(/(?:@[a-zA-Z0-9_-]+)?(?:\/|$)/)
.map((segment, i, segments) => {
const decoded_segment = decodeURIComponent(segment);
// special case — /[...rest]/ could contain zero segments
const match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(segment);
const match = /^\[\.\.\.(\w+)(?:=(\w+))?\]$/.exec(decoded_segment);
if (match) {
names.push(match[1]);
types.push(match[2]);
Expand All @@ -30,9 +31,9 @@ export function parse_route_id(id) {
const is_last = i === segments.length - 1;

return (
segment &&
decoded_segment &&
'/' +
segment
decoded_segment
.split(/\[(.+?)\]/)
.map((content, i) => {
if (i % 2) {
Expand Down
10 changes: 10 additions & 0 deletions packages/kit/src/utils/routing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ const tests = {
pattern: /^\/matched\/([^/]+?)\/?$/,
names: ['id'],
types: ['uuid']
},
'%23hash-encoded': {
pattern: /^\/%23hash-encoded\/?$/,
names: [],
types: []
},
'%40at-encoded/[id]': {
pattern: /^\/@at-encoded\/([^/]+?)\/?$/,
names: ['id'],
types: [undefined]
}
};

Expand Down