Skip to content

Commit

Permalink
fix: required parameters placed after missing optional parameters are…
Browse files Browse the repository at this point in the history
… no longer skipped (#9331)

* fix: required parameters placed after missing optional parameters are no longer skipped

* Update .changeset/loud-ghosts-worry.md

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>

---------

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
  • Loading branch information
glennsayers and benmccann committed Mar 6, 2023
1 parent 83f7667 commit a71b5e6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/loud-ghosts-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': fix
---

fix: don't skip required parameters after missing optional parameters
2 changes: 1 addition & 1 deletion packages/kit/src/utils/routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export function exec(match, params, matchers) {
// and the next value is defined, otherwise the buffer will cause us to skip values
const next_param = params[i + 1];
const next_value = values[i + 1];
if (next_param && !next_param.rest && next_value) {
if (next_param && !next_param.rest && next_param.optional && next_value) {
buffered = 0;
}
continue;
Expand Down
5 changes: 5 additions & 0 deletions packages/kit/src/utils/routing.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ const exec_tests = [
route: '/[[slug1=doesntmatch]]/[[slug2=matches]]/constant/[[slug3=matches]]',
path: '/b/constant/c',
expected: { slug2: 'b', slug3: 'c' }
},
{
route: '/[[slug1=doesntmatch]]/[slug2=matches]/[slug3]',
path: '/a/b/c',
expected: undefined
}
];

Expand Down

0 comments on commit a71b5e6

Please sign in to comment.