-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Path to regexp fix #11965
Closed
Closed
Path to regexp fix #11965
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4fa4d1
Updated packages. path-to-regexp to latest version
hkbertoson 02a0340
Changeset
hkbertoson 45b7e2a
Updated generator function
hkbertoson fd0c086
Update generator.ts
hkbertoson 0e07ae7
Refactor parameter sanitization and array preservation
hkbertoson a06cfaa
Merge branch 'main' into path-to-regexp-fix
hkbertoson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'astro': minor | ||
--- | ||
|
||
Updated path-to-regexp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removes this part from being a parameter understood by
path-to-regexp
to just being a literal, e.g. if the route was[...slug]
, previously this template literal created:slug(.*)
but after this change it just createsslug
. That’s probably why a lot of tests are failing.We’ll need to check how to match the
(.*)
behaviour in the latest version ofpath-to-regexp
(if possible).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From taking a look at the docs, it seems like this might be the way?
In a quick sandbox I spun up I ran this code:
Which logged
/one/two/three/four
as expected. We’d still need to see if it fully matches all behaviour specified in tests though or if there are edge cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this as well. It errors out and says "expected "slug" to be a non-empty array"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I guess currently we allow
[...spread]
to match nothing (i.e.[...spread]
can match/
) and*spread
inpath-to-regexp
doesn’t include support for an optional segment. They do mention{}
for optional segments, could try combining that with the wildcard?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then there is still the issue with the actual parameter value for rest (...) parameters, today it's "somedir/file.ext" and with the new version it should be ["somedir", "file.ext"], i.e. the parameter value needs to be split.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, when I did a quick investigation it looked like
path-to-regexp
already expected an array in v6, so assumed that hadn’t changed, but I may have misunderstood.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I made some changes and im testing it all now to see.