From a71b5e69ef37ce46e8e8590d537036cb7e267d51 Mon Sep 17 00:00:00 2001 From: Glenn Sayers Date: Mon, 6 Mar 2023 15:28:13 +0000 Subject: [PATCH] fix: required parameters placed after missing optional parameters are 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> --- .changeset/loud-ghosts-worry.md | 5 +++++ packages/kit/src/utils/routing.js | 2 +- packages/kit/src/utils/routing.spec.js | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 .changeset/loud-ghosts-worry.md diff --git a/.changeset/loud-ghosts-worry.md b/.changeset/loud-ghosts-worry.md new file mode 100644 index 000000000000..182e94259c5a --- /dev/null +++ b/.changeset/loud-ghosts-worry.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': fix +--- + +fix: don't skip required parameters after missing optional parameters diff --git a/packages/kit/src/utils/routing.js b/packages/kit/src/utils/routing.js index 30461f8c56be..a5a9fdb938af 100644 --- a/packages/kit/src/utils/routing.js +++ b/packages/kit/src/utils/routing.js @@ -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; diff --git a/packages/kit/src/utils/routing.spec.js b/packages/kit/src/utils/routing.spec.js index 93a886b20ad3..4ba8737fe479 100644 --- a/packages/kit/src/utils/routing.spec.js +++ b/packages/kit/src/utils/routing.spec.js @@ -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 } ];