fix(server): update catch-all to /{*path} and suppress conflict panic - #35
Merged
Conversation
Member
|
Hi @skick1234 , thank you so much for fixing it! 😁 |
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.
Problem
When adding a wildcard node (
{*path}) at the same level as an existing parameter node (/{foo}), matchit attempts to detect this forbidden conflict. It should return a conflict error. However, because{*path}is missing the leading slash, it has 0 common characters with the existing route. The matchit logic blindly checks the character before the common part (index - 1), causing an integer underflow panic (crash) instead of returning the proper error. (#34)Solution
Since the upstream matchit library has not yet resolved the integer underflow bug, I changed the default catch-all registration to
/{*path}. Crucially, it avoids the crash path in matchit. Instead of panicking, it throws a standard conflict error.We wrapped this registration in a try-catch block. This allows us to catch that conflict error and prevent the server from crashing when a parameter node (e.g.,
/:id) is present.