Skip to content

fix: match URL-encoded newlines in rest route params #14102

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

Merged
merged 5 commits into from
Aug 6, 2025
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/dark-heads-greet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: match URL-encoded newlines in rest route params
4 changes: 2 additions & 2 deletions packages/adapter-vercel/test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ test('pattern_to_src for route with optional parameter in the middle', () => {
});

test('pattern_to_src for route with rest parameter', () => {
run_pattern_to_src_test('/foo/[...bar]', '^/foo(/.*)?/?');
run_pattern_to_src_test('/foo/[...bar]', '^/foo(/[^]*)?/?');
});

test('pattern_to_src for route with rest parameter in the middle', () => {
run_pattern_to_src_test('/foo/[...bar]/baz', '^/foo(/.*)?/baz/?');
run_pattern_to_src_test('/foo/[...bar]/baz', '^/foo(/[^]*)?/baz/?');
});
10 changes: 5 additions & 5 deletions packages/kit/src/core/sync/create_manifest_data/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ test('sorts routes with rest correctly', () => {
},
{
id: '/a/[...rest]',
pattern: '/^/a(?:/(.*))?/?$/',
pattern: '/^/a(?:/([^]*))?/?$/',
page: { layouts: [0], errors: [1], leaf: 2 }
},
{
Expand All @@ -277,7 +277,7 @@ test('sorts routes with rest correctly', () => {
},
{
id: '/b/[...rest]',
pattern: '/^/b(?:/(.*))?/?$/',
pattern: '/^/b(?:/([^]*))?/?$/',
page: { layouts: [0], errors: [1], leaf: 3 }
}
]);
Expand All @@ -301,12 +301,12 @@ test('allows rest parameters inside segments', () => {
},
{
id: '/prefix-[...rest]',
pattern: '/^/prefix-(.*?)/?$/',
pattern: '/^/prefix-([^]*?)/?$/',
page: { layouts: [0], errors: [1], leaf: 2 }
},
{
id: '/[...rest].json',
pattern: '/^/(.*?).json/?$/',
pattern: '/^/([^]*?).json/?$/',
endpoint: {
file: 'samples/rest-prefix-suffix/[...rest].json/+server.js'
}
Expand Down Expand Up @@ -714,7 +714,7 @@ test('handles pages without .svelte file', () => {
},
{
id: '/error/[...path]',
pattern: '/^/error(?:/(.*))?/?$/',
pattern: '/^/error(?:/([^]*))?/?$/',
page: { layouts: [0, undefined], errors: [1, 2], leaf: 6 }
},
{
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/utils/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function parse_route_id(id) {
rest: true,
chained: true
});
return '(?:/(.*))?';
return '(?:/([^]*))?';
}
// special case — /[[optional]]/ could contain zero segments
const optional_match = /^\[\[(\w+)(?:=(\w+))?\]\]$/.exec(segment);
Expand Down Expand Up @@ -86,7 +86,7 @@ export function parse_route_id(id) {
rest: !!is_rest,
chained: is_rest ? i === 1 && parts[0] === '' : false
});
return is_rest ? '(.*?)' : is_optional ? '([^/]*)?' : '([^/]+?)';
return is_rest ? '([^]*?)' : is_optional ? '([^/]*)?' : '([^/]+?)';
}

return escape(content);
Expand Down
14 changes: 12 additions & 2 deletions packages/kit/src/utils/routing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ describe('parse_route_id', () => {
params: [{ name: 'slug', matcher: undefined, optional: true, rest: false, chained: false }]
},
'/[...catchall]': {
pattern: /^(?:\/(.*))?\/?$/,
pattern: /^(?:\/([^]*))?\/?$/,
params: [{ name: 'catchall', matcher: undefined, optional: false, rest: true, chained: true }]
},
'/foo/[...catchall]/bar': {
pattern: /^\/foo(?:\/(.*))?\/bar\/?$/,
pattern: /^\/foo(?:\/([^]*))?\/bar\/?$/,
params: [{ name: 'catchall', matcher: undefined, optional: false, rest: true, chained: true }]
},
'/matched/[id=uuid]': {
Expand Down Expand Up @@ -244,6 +244,16 @@ describe('exec', () => {
route: '/[[slug1=doesntmatch]]/[...slug2=doesntmatch]',
path: '/a/b/c',
expected: undefined
},
{
route: '/[...catchall]',
path: '/\n',
expected: { catchall: '\n' }
},
{
route: '/[[...catchall]]',
path: '/\n',
expected: { catchall: '\n' }
}
];

Expand Down
Loading