Skip to content

Commit 6692c1f

Browse files
authored
fix: allow rest params to be empty in resolvePath (#10146)
fixes #10140
1 parent ff53e7d commit 6692c1f

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.changeset/metal-toes-talk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
fix: allow rest params to be empty in resolvePath

packages/kit/src/exports/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export function fail(status, data) {
104104
return new ActionFailure(status, data);
105105
}
106106

107-
const basic_param_pattern = /\[(\[)?(?:\.\.\.)?(\w+?)(?:=(\w+))?\]\]?/g;
107+
const basic_param_pattern = /\[(\[)?(\.\.\.)?(\w+?)(?:=(\w+))?\]\]?/g;
108108

109109
/**
110110
* Populate a route ID with params to resolve a pathname.
@@ -128,12 +128,13 @@ export function resolvePath(id, params) {
128128
'/' +
129129
segments
130130
.map((segment) =>
131-
segment.replace(basic_param_pattern, (_, optional, name) => {
131+
segment.replace(basic_param_pattern, (_, optional, rest, name) => {
132132
const param_value = params[name];
133133

134134
// This is nested so TS correctly narrows the type
135135
if (!param_value) {
136136
if (optional) return '';
137+
if (rest && param_value !== undefined) return '';
137138
throw new Error(`Missing parameter '${name}' in route ${id}`);
138139
}
139140

packages/kit/src/exports/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ const from_params_tests = [
2222
params: { one: 'one', two: '2', three: '3' },
2323
expected: '/blog/one/2-and-3'
2424
},
25+
{
26+
route: '/blog/[...one]',
27+
params: { one: '' },
28+
expected: '/blog'
29+
},
2530
{
2631
route: '/blog/[one]/[...two]-not-three',
2732
params: { one: 'one', two: 'two/2' },

0 commit comments

Comments
 (0)