go-chi / go-chi/chi

Expecting 405, getting routed to a param path instead

Open
#1,035 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
22.8k
Forks
1.2k
Avg merge
5h 17m
Merged PRs (30d)
10

Description

When I use regex with a path such as `/users/{id:[0-9]+}` this works really well to prevent static paths such as `/users/me` from being matched incorrectly. That is an issue of it's own really, and I was expecting go-chi to have better static matching than it does. Anyway, the regex on the path variable fixed that, however, it does not work when you have an additional subpath. For instance, when I create a route for `/profiles/{id:[0-9]+}/usage` this throws a 404 not found. The only way to make it work is to remove the regex, and then it's not the same style as the others where I must use `{id:[0-9]+}`

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported routes `/users/{id:[0-9]+}` and `/profiles/{id:[0-9]+}/usage` in a small Go router test. Trace how chi handles regex parameters followed by a subpath and compare the resulting 404 and method behavior. Done means the constrained nested route matches as expected without regressing static-path matching.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.