-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Route matching too greedy: parsed segments may contain segment seperators #785
Comments
If the defined route is |
I concur. |
@ChrisBrandhorst @chandu and I whole heatedly dis-concur. The route parameters were, explicitly, designed to be greedy by nature in the You could for example
|
Indeed I've already used the first suggestion you make: using a custom regex parameter in my route. However, in my project this behaviour is required in many places, so I thank you for your pointers on how to implement a custom pattern matcher (although I personally don't like that I now will need to copy the entire Although I respect your opinion, I don't understand it :-) |
Other frameworks use both parameters and splats (I think this is what @ChrisBrandhorst is referring to when he mentioned other routing mechanisms). A parameter could be defined as {containerid} and a splat as {*containerid}. |
@ChrisBrandhorst @codeprogression this is something we've been talking about the last couple of days and there are some things that needs to be ironed out before we can make a definite decision. Any changes to this would probably
|
@codeprogression Correct. |
Suppose we have the route
/containers/{containerId}/contents
.If we request
/containers/4/something/contents
, this route will be matched andcontainerId
will get a value of4/something
.This seems counter-intuitive. I would expect
{containerId}
to only match a single path segment and think the currently implemented greedy alternative is a far less occurring situation.The documentation seems to suggest this is by design. Is this really the case? If it is, I am interested in the reasoning behind this (since it conflicts with all the other routing mechanism I know of).
My proposed fix is not to match any character in a segment, but any non-slash character. Change at
DefaultPatternMatcher#ParameterizeSegment
line 141:@"(?<{0}>.+?)"
becomes
@"(?<{0}>[^\/]+?)"
If one then actually wants to match the segment seperator, (s)he can always use the original RegEx:
?<foo>.+?
.The text was updated successfully, but these errors were encountered: