fix: reject wildcard array that compiles to an empty path#448
Open
spokodev wants to merge 1 commit into
Open
Conversation
compile("/*foo")({ foo: [""] }) returned "/", which the same
pattern never matches, so the value is silently lost. A wildcard's
value domain is exactly what match produces (capturedValue.split(delimiter)),
and match can never yield [""] because the capture requires at least one
character. Mirror the empty-string param rejection and throw when the
wildcard yields an empty path. Arrays with empty segments (e.g.
["a", ""]) still round-trip and are unaffected.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #448 +/- ##
=======================================
Coverage 99.75% 99.75%
=======================================
Files 1 1
Lines 400 403 +3
Branches 161 163 +2
=======================================
+ Hits 399 402 +3
Misses 1 1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
compilefor a wildcard accepts an array whose only content is empty, and silently returns a path the same pattern can never match:The value is lost with no error. This is the array counterpart of the empty-string param case rejected in #444.
A wildcard's value domain is exactly what
matchproduces —capturedValue.split(delimiter)— andmatchcan never yield[""], since the capture group requires at least one character. So there is no input for which[""]is a correct value;compileshould reject it rather than emit an unmatchable path.The fix throws when the joined output is empty. Arrays that contain empty segments but still produce content (e.g.
["a", ""]→"/a/",["route", "nested", ""]→"/route/nested/") are whatmatchreturns for trailing/empty segments and continue to round-trip unchanged.Adds a regression test.