fix issues with complex multi-param#349
Merged
Merged
Conversation
Contributor
Author
|
Well, test on Node.js 26 still depends on #348. |
jimmyolo
added a commit
to jimmyolo/ultimate-express
that referenced
this pull request
Jul 21, 2026
Cross-model review (Codex) found that dropping the boundary lookahead let a custom capture that can match empty (e.g. `:p(.*)` or `:p([^-]*)`) match an empty param before a following literal — `/x/:p(.*)-end` matched `/x/-end`, which Express (path-to-regexp@0.1.13) rejects. The prior lookahead form was also wrong here (it rejected the non-empty `/x/abc-end` that Express accepts), so neither form matched the oracle. path-to-regexp compiles a custom capture's first `*` to `(.*)`, turning `.*` into `.(.*)` and `[^-]*` into `[^-](.*)` — forcing >=1 char. Replicate that one transform on the captured regex. Differential-verified against path-to-regexp@0.1.13: 0 divergences across the `.*`/`[^-]*` empty-and-nonempty cases, PR dimdenGD#349's multi-param cases, and the alternation-before-literal case. New parity assertions `/opt/:p(.*)-end` -> `/opt/-end` (404) and `/opt/abc-end` (match); red without this change. Reviewed-by: Codex gpt-5-codex Assisted-by: claude:claude-opus-4-8 (medium)
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.
This PR fixes multiple issues with the current matching strategy with regards to multi-param routes:
-and.as they are not meant verbatim there([^/]+)), but are wrongly optimized (happening in app but not router, which confused me a lot initially)The ideas come from my personal use case and the official Express.js 4.x documentation, with the official
path-to-regexp0.1.x as a loose reference.Not sure if the test cases are okay like this (may need to reorganize), but they definitely serve the purpose of identifying the exact problems with the current implementation.