-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] A route requirements failure is overridden by a method failure #22739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I don't think it's a bug. Considering the test you wrote, the behavior looks legit to me: |
Maybe Btw,
|
I did see it actually: the
It may seem less legit with this example, but it entirely depends what you do inside your condition and what you assume it should return. For instance, for api versioning, I might use something like:
The So in most of the cases, I'd say |
A resource is identified by a URI:
So if we take (https was a bad example as it is a part of URI and http/https resources should be considered as different ones) public function testRequirementFailureIsNotOverridenWithMethodFailure()
{
$coll = new RouteCollection();
$coll->add('foo1', new Route('/foo', array(), array(), array(), '', array(), array('get')));
$coll->add('foo2', new Route('/foo', array(), array(), array(), '', array(), array('post'), 'equest.getContentType() == 'json''));
$matcher = new UrlMatcher($coll, new RequestContext('', 'POST'));
$matcher->match('/foo');
} Both In case of you example the current behavior will work out correctly. Its semantics is clear and So seems that the both behaviors (current one or For me |
You're right. A I believe when you're using routes with such conditions on the request format and expect a proper |
What about something like |
imply that a request is what matched through this service. Therefore my assumption is that tests are not scopes by URI, method and some excluding conditions, the testing of request headers supposed to be legal. The example in the docs seems like a confirmation: condition: "context.getMethod() in ['GET', 'HEAD'] and request.headers.get('User-Agent') matches '/firefox/i'" And if a testing of |
Unless I misunderstood the issue, this has been fixed in #26100 |
…match (nicolas-grekas) This PR was merged into the 2.7 branch. Discussion ---------- [Routing] Don't throw 405 when scheme requirement doesn't match | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22739 | License | MIT | Doc PR | - Commits ------- 9d70ef0 [Routing] Don't throw 405 when scheme requirement doesn't match
Uh oh!
There was an error while loading. Please reload this page.
I faced with the error that when you have routes with same paths, different methods and one of the routes has a condition. If the condition will fail during matching,
UrlMatcher
will throwMethodNotAllowedException
with an incorrect set of allowed methods while it seems supposed to throwResourceNotFoundException
on a failed condition.This test can reproduce the issue:
The solution for
UrlMatcher
should not be a hard task but there is also the matcher produced byPhpMatcherDumper
which logic seems inverted towardsUrlMatcher
's logic (i.e.: the condition is checked before the method).The text was updated successfully, but these errors were encountered: