Skip to content

Commit 1e2c826

Browse files
fix: successive optional route parameters can now be empty (#9266)
* Optional chained parameters can be skipped - close #9261 * Update changeset description Co-authored-by: Ben McCann <[email protected]> --------- Co-authored-by: Ben McCann <[email protected]>
1 parent 99c970f commit 1e2c826

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

.changeset/nasty-guests-sing.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: successive optional route parameters can now be empty

packages/kit/src/utils/routing.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ export function exec(match, params, matchers) {
152152

153153
if (!param.matcher || matchers[param.matcher](value)) {
154154
result[param.name] = value;
155+
156+
// Now that the params match, reset the buffer if the next param isn't the [...rest]
157+
// and the next value is defined, otherwise the buffer will cause us to skip values
158+
const next_param = params[i + 1];
159+
const next_value = values[i + 1];
160+
if (next_param && !next_param.rest && next_value) {
161+
buffered = 0;
162+
}
155163
continue;
156164
}
157165

packages/kit/src/utils/routing.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ const exec_tests = [
187187
route: '/[[a=doesntmatch]]/[[b=matches]]/c',
188188
path: '/a/b/c',
189189
expected: undefined
190+
},
191+
{
192+
route: '/[[slug1=matches]]/[[slug2=matches]]/constant/[[slug3=matches]]',
193+
path: '/a/b/constant/c',
194+
expected: { slug1: 'a', slug2: 'b', slug3: 'c' }
195+
},
196+
{
197+
route: '/[[slug1=doesntmatch]]/[[slug2=matches]]/constant/[[slug3=matches]]',
198+
path: '/b/constant/c',
199+
expected: { slug2: 'b', slug3: 'c' }
190200
}
191201
];
192202

0 commit comments

Comments
 (0)