fix: support wildcard ports in url matching#2677
Merged
kettanaito merged 4 commits intomswjs:mainfrom Mar 20, 2026
Merged
Conversation
Escape wildcard port separators in coercePath so absolute URLs like http://localhost:* and ws://localhost:* match without throwing. Add regression coverage for HTTP and WebSocket patterns, including a pathname case. Fixes mswjs#2204
Member
|
Hi, @trknhr. Thanks for opening this! I've added a few missing test cases and they are failing at the moment. I don't believe your suggestion has truly implemented the behavior that the users expect. I might take a look at this once I have a moment. Hopefully, shouldn't be a big change. |
kettanaito
reviewed
Mar 19, 2026
kettanaito
approved these changes
Mar 20, 2026
Member
kettanaito
left a comment
There was a problem hiding this comment.
This looks good and the expectations align with #2678.
Member
|
Thank you for fixing the issue! 👏 |
Member
Released: v2.12.14 🎉This has been released in v2.12.14. Get these changes by running the following command: Predictable release automation by Release. |
1 task
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.
Support absolute URLs that use wildcard ports in request matching.
MSW already coerces request masks before passing them to
path-to-regexp. Numeric ports were escaped there, but wildcard ports likehttp://localhost:*were left as:(.*), whichpath-to-regexpinterprets as an invalid parameter declaration and throws.This updates
coercePath()to escape the port separator when the port is either numeric or a wildcard-expanded capture group. It also adds regression tests for HTTP and WebSocket URLs, including a pathname case.This keeps the current
path-to-regexp-based matching behavior intact instead of broadening the fix into a larger matcher change.Fixes #2204