Fix 404 on regexp path params containing a segment delimiter#1115
Open
greymoth-jp wants to merge 1 commit into
Open
Fix 404 on regexp path params containing a segment delimiter#1115greymoth-jp wants to merge 1 commit into
greymoth-jp wants to merge 1 commit into
Conversation
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
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.
A regexp path-param value that contains a segment-trailing delimiter returns 404 — e.g. a UUID
8-4-4-4-12preceded by a-{date}segment — becausefindRoutesplits on the first delimiter byte and truncates the value. The fix intree.gomatches the full regexp segment. Verified both ways.