Skip to content

fix: required parameters placed after missing optional parameters are no longer skipped - #9331

Merged
Rich-Harris merged 2 commits into
sveltejs:masterfrom
glennsayers:gh-9304
Mar 6, 2023
Merged

fix: required parameters placed after missing optional parameters are no longer skipped#9331
Rich-Harris merged 2 commits into
sveltejs:masterfrom
glennsayers:gh-9304

Conversation

@glennsayers

Copy link
Copy Markdown
Contributor

Due to multiple matching routes, exec is called for [[param1=required]]/[param2=param2]/[param3] even though we’ve provided 3 parameters which should correlate to the /[param2=param2]/[param3]/[param4] route.

The code flow was finishing with a buffer size of 0, which was incorrectly telling Kit that the route was a match. As such it wasn't attempting to parse other routes to check for a match, despite the fact there was still a required parameter that hadn't been matched.

This situation doesn’t appear to be covered under current unit tests as the tests load one route at a time. I've added a new Playwright test to cover this scenario.

Fixes #9304

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

@dummdidumm dummdidumm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Can you turn this into a unit test? I believe you can get the same outcome if you test that the route in question is not matched (by setting expected: undefined)

@glennsayers

Copy link
Copy Markdown
Contributor Author

Sure @dummdidumm ! Do you want me to keep the playwright test or replace it?

@dummdidumm

Copy link
Copy Markdown
Member

replace them

Comment thread .changeset/loud-ghosts-worry.md Outdated
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
@Rich-Harris
Rich-Harris merged commit a71b5e6 into sveltejs:master Mar 6, 2023
@Rich-Harris

Copy link
Copy Markdown
Member

Thank you! Happy the fix turned out to be so simple

@@ -0,0 +1,5 @@
---
'@sveltejs/kit': fix

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi, this needed to be patch. releases are failing because this is an invalid value: #9365

@github-actions github-actions Bot mentioned this pull request Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Second non-optional parameter is skipped when root optional parameter is not matched

4 participants