Skip to content

fix: reject wildcard array that compiles to an empty path#448

Open
spokodev wants to merge 1 commit into
pillarjs:masterfrom
spokodev:fix/reject-empty-wildcard
Open

fix: reject wildcard array that compiles to an empty path#448
spokodev wants to merge 1 commit into
pillarjs:masterfrom
spokodev:fix/reject-empty-wildcard

Conversation

@spokodev

@spokodev spokodev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

compile for a wildcard accepts an array whose only content is empty, and silently returns a path the same pattern can never match:

compile("/*foo")({ foo: [""] }); //=> "/"
match("/*foo")("/");             //=> false

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 match produces — capturedValue.split(delimiter) — and match can never yield [""], since the capture group requires at least one character. So there is no input for which [""] is a correct value; compile should 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 what match returns for trailing/empty segments and continue to round-trip unchanged.

Adds a regression test.

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

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.75%. Comparing base (c83a925) to head (5a7a44d).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant