Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Mar 6, 2023

Conversation

glennsayers
Copy link
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:.

Copy link
Member

@dummdidumm dummdidumm left a comment

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
Contributor Author

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

@dummdidumm
Copy link
Member

replace them

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
Member

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

@@ -0,0 +1,5 @@
---
'@sveltejs/kit': fix
Copy link
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