-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[WebProfiler] adding a condition in routing.yml breaks the router panel #17342
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
Is it valid? '/dev\.local/'" Because of the backslash, I get this exception:
After removing it, or adding a plus backslash, I can't reproduce the error at ?panel=router. condition: "request.server.get('HTTP_HOST') matches '/dev.local/'" |
I think it is valid : I used evaluate method from ExpressionLanguage class to validate the condition and it was ok. How did you get the I tried your solution : using condition: "request.server.get('HTTP_HOST') matches '/dev.local/'" I still have the same exception |
The error from @paradajozsef is that the @brunoroux please provide the full backtrace of exceptions (you should have a section of the error page giving it as plaintext at the bottom of the page IIRC) |
Okay thanks for pointing out the escaping part. Here is the backtrace :
After looking at the stack trace a bit more closely it seeems that the request is null |
I've investigated this problem and the error occurs in these lines of return new Response($this->twig->render('@WebProfiler/Router/panel.html.twig', array(
'request' => $request,
'router' => $profile->getCollector('router'),
'traces' => $matcher->getTraces($request->getPathInfo()), // <-- THIS IS THE ERROR
)), 200, array('Content-Type' => 'text/html')); If I remove that line, or if I remove the expression in the routing condition, everything works right. This the dump of the |
The problem is here TraceableUrlMatcher.php#L98 and here UrlMatcher.php#L210 class TraceableUrlMatcher extends UrlMatcher
{
//...
protected function matchCollection($pathinfo, RouteCollection $routes)
{
//...
// check condition
if ($condition = $route->getCondition()) {
if (!$this->getExpressionLanguage()->evaluate($condition, array('context' => $this->context, 'request' => $this->request))) { // <-- here
$this->addTrace(sprintf('Condition "%s" does not evaluate to "true"', $condition), self::ROUTE_ALMOST_MATCHES, $name, $route);
continue;
}
}
//...
}
} Always that we use In this case Maybe we need adds a new method to +use Symfony\Component\HttpFoundation\Request;
class TraceableUrlMatcher extends UrlMatcher
{
//...
+ public function getTracesRequest(Request $request)
+ {
+ $this->request = $request;
+
+ $ret = $this->getTraces($request->getPathInfo());
+
+ $this->request = null;
+
+ return $ret;
+ }
} |
…aviereguiluz) This PR was squashed before being merged into the 2.7 branch (closes #17744). Discussion ---------- Improve error reporting in router panel of web profiler | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17342 | License | MIT | Doc PR | - ### Problem If you define a route condition like this: ```yaml app: resource: '@AppBundle/Controller/' type: annotation condition: "request.server.get('HTTP_HOST') matches '/.*\.dev/'" ``` When browsing the Routing panel in the web profiler, you see an exception:  #### Why? Because the route condition uses the `request` object, but the special `TraceableUrlMatcher` class doesn't get access to the real `request` object but to the special object obtained via: ```php $request = $profile->getCollector('request'); ``` These are the contents of this pseudo-request:  `request.server.get(...)` condition fails because `request.server` is `null`. The full exception message shows this:  ### Solution I propose to catch all exceptions in `TraceableUrlMatcher` and display an error message with some details of the exception:  Commits ------- 1001554 Improve error reporting in router panel of web profiler
…iler (javiereguiluz) This PR was squashed before being merged into the 2.7 branch (closes symfony#17744). Discussion ---------- Improve error reporting in router panel of web profiler | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#17342 | License | MIT | Doc PR | - ### Problem If you define a route condition like this: ```yaml app: resource: '@AppBundle/Controller/' type: annotation condition: "request.server.get('HTTP_HOST') matches '/.*\.dev/'" ``` When browsing the Routing panel in the web profiler, you see an exception:  #### Why? Because the route condition uses the `request` object, but the special `TraceableUrlMatcher` class doesn't get access to the real `request` object but to the special object obtained via: ```php $request = $profile->getCollector('request'); ``` These are the contents of this pseudo-request:  `request.server.get(...)` condition fails because `request.server` is `null`. The full exception message shows this:  ### Solution I propose to catch all exceptions in `TraceableUrlMatcher` and display an error message with some details of the exception:  Commits ------- 1001554 Improve error reporting in router panel of web profiler
Adding a condition (using a regex match on the HTTP_HOST of the request) in my routing.yml breaks the WebProfiler router panel.
My routing.yml is as follows :
The minimum reproducing repo can be found here : https://github.com/brunoroux/symfony-standard/tree/bug/profiler
Accessing : http://dev.local/app_dev.php/_profiler/6ae9ed?panel=router throws a Twig_Error_Runtime :
An exception has been thrown during the rendering of a template ("Unable to get a property on a non-object.") in @WebProfiler/Collector/router.html.twig at line 13.
Edit : Forgot to mention that used version is 2.8
The text was updated successfully, but these errors were encountered: