Skip to content

fix(server): update catch-all to /{*path} and suppress conflict panic - #35

Merged
nehu3n merged 1 commit into
kitojs:mainfrom
skick1234:main
Dec 17, 2025
Merged

fix(server): update catch-all to /{*path} and suppress conflict panic#35
nehu3n merged 1 commit into
kitojs:mainfrom
skick1234:main

Conversation

@skick1234

Copy link
Copy Markdown
Contributor

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.

@nehu3n
nehu3n merged commit 8556c98 into kitojs:main Dec 17, 2025
2 checks passed
@nehu3n

nehu3n commented Dec 17, 2025

Copy link
Copy Markdown
Member

Hi @skick1234 , thank you so much for fixing it! 😁

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.

2 participants