Skip to content

Fix 404 on regexp path params containing a segment delimiter#1115

Open
greymoth-jp wants to merge 1 commit into
go-chi:masterfrom
greymoth-jp:fix/regexp-param-tail-in-value
Open

Fix 404 on regexp path params containing a segment delimiter#1115
greymoth-jp wants to merge 1 commit into
go-chi:masterfrom
greymoth-jp:fix/regexp-param-tail-in-value

Conversation

@greymoth-jp

Copy link
Copy Markdown

A regexp path-param value that contains a segment-trailing delimiter returns 404 — e.g. a UUID 8-4-4-4-12 preceded by a -{date} segment — because findRoute splits on the first delimiter byte and truncates the value. The fix in tree.go matches the full regexp segment. Verified both ways.

A regexp param can legitimately capture a value that includes the byte
used as the delimiter before the next part of the same path segment, for
example a UUID ("8-4-4-4-12") followed by a literal "-" and another
param: /test/{uuid:[0-9a-f]{8}-...-[0-9a-f]{12}}-{date}.

findRoute split the search string at the first occurrence of the tail
delimiter, which truncated the value (e.g. to the first 8 hex chars) so
the anchored regexp never matched and the route fell through to 404.

For regexp param nodes, advance to subsequent occurrences of the tail
delimiter within the same path segment until the regexp matches, instead
of giving up after the first. Non-regexp params and cross-segment guards
are unchanged.

Fixes go-chi#970
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.

1 participant