Enforce UTF-8 charset for core controllers
This commit is contained in:
parent
31bfc9508b
commit
3032014fd9
@ -51,7 +51,7 @@ class ExceptionController
|
|||||||
|
|
||||||
$code = $exception->getStatusCode();
|
$code = $exception->getStatusCode();
|
||||||
|
|
||||||
return new Response($this->twig->render(
|
return Response::create($this->twig->render(
|
||||||
(string) $this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug),
|
(string) $this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug),
|
||||||
array(
|
array(
|
||||||
'status_code' => $code,
|
'status_code' => $code,
|
||||||
@ -60,7 +60,7 @@ class ExceptionController
|
|||||||
'logger' => $logger,
|
'logger' => $logger,
|
||||||
'currentContent' => $currentContent,
|
'currentContent' => $currentContent,
|
||||||
)
|
)
|
||||||
));
|
))->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,6 +39,7 @@ class ExceptionControllerTest extends TestCase
|
|||||||
$request->headers->set('X-Php-Ob-Level', 1);
|
$request->headers->set('X-Php-Ob-Level', 1);
|
||||||
|
|
||||||
$controller = new ExceptionController($twig, false);
|
$controller = new ExceptionController($twig, false);
|
||||||
$controller->showAction($request, $flatten);
|
$response = $controller->showAction($request, $flatten);
|
||||||
|
$this->assertEquals('UTF-8', $response->getCharset(), 'Request charset is explicitly set to UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,16 +62,17 @@ class ExceptionController
|
|||||||
|
|
||||||
$code = $exception->getStatusCode();
|
$code = $exception->getStatusCode();
|
||||||
|
|
||||||
return new Response($this->twig->render(
|
return Response::create(
|
||||||
$template,
|
$this->twig->render($template, array(
|
||||||
array(
|
|
||||||
'status_code' => $code,
|
'status_code' => $code,
|
||||||
'status_text' => Response::$statusTexts[$code],
|
'status_text' => Response::$statusTexts[$code],
|
||||||
'exception' => $exception,
|
'exception' => $exception,
|
||||||
'logger' => null,
|
'logger' => null,
|
||||||
'currentContent' => '',
|
'currentContent' => '',
|
||||||
)
|
)),
|
||||||
), 200, array('Content-Type' => 'text/html'));
|
200,
|
||||||
|
array('Content-Type' => 'text/html')
|
||||||
|
)->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -97,10 +98,14 @@ class ExceptionController
|
|||||||
if (!$this->templateExists($template)) {
|
if (!$this->templateExists($template)) {
|
||||||
$handler = new ExceptionHandler();
|
$handler = new ExceptionHandler();
|
||||||
|
|
||||||
return new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css'));
|
$response = new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css'));
|
||||||
|
} else {
|
||||||
|
$response = new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, array('Content-Type' => 'text/css'));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, array('Content-Type' => 'text/css'));
|
$response->setCharset('UTF-8');
|
||||||
|
|
||||||
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getTemplate()
|
protected function getTemplate()
|
||||||
|
@ -99,16 +99,20 @@ class ProfilerController
|
|||||||
throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token));
|
throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response($this->twig->render($this->getTemplateManager()->getName($profile, $panel), array(
|
return Response::create(
|
||||||
'token' => $token,
|
$this->twig->render($this->getTemplateManager()->getName($profile, $panel), array(
|
||||||
'profile' => $profile,
|
'token' => $token,
|
||||||
'collector' => $profile->getCollector($panel),
|
'profile' => $profile,
|
||||||
'panel' => $panel,
|
'collector' => $profile->getCollector($panel),
|
||||||
'page' => $page,
|
'panel' => $panel,
|
||||||
'request' => $request,
|
'page' => $page,
|
||||||
'templates' => $this->getTemplateManager()->getTemplates($profile),
|
'request' => $request,
|
||||||
'is_ajax' => $request->isXmlHttpRequest(),
|
'templates' => $this->getTemplateManager()->getTemplates($profile),
|
||||||
)), 200, array('Content-Type' => 'text/html'));
|
'is_ajax' => $request->isXmlHttpRequest(),
|
||||||
|
)),
|
||||||
|
200,
|
||||||
|
array('Content-Type' => 'text/html')
|
||||||
|
)->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -147,9 +151,13 @@ class ProfilerController
|
|||||||
|
|
||||||
$this->profiler->disable();
|
$this->profiler->disable();
|
||||||
|
|
||||||
return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array(
|
return Response::create(
|
||||||
'about' => $about,
|
$this->twig->render('@WebProfiler/Profiler/info.html.twig', array(
|
||||||
)), 200, array('Content-Type' => 'text/html'));
|
'about' => $about,
|
||||||
|
)),
|
||||||
|
200,
|
||||||
|
array('Content-Type' => 'text/html')
|
||||||
|
)->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,13 +205,17 @@ class ProfilerController
|
|||||||
// the profiler is not enabled
|
// the profiler is not enabled
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response($this->twig->render('@WebProfiler/Profiler/toolbar.html.twig', array(
|
return Response::create(
|
||||||
'position' => $position,
|
$this->twig->render('@WebProfiler/Profiler/toolbar.html.twig', array(
|
||||||
'profile' => $profile,
|
'position' => $position,
|
||||||
'templates' => $this->getTemplateManager()->getTemplates($profile),
|
'profile' => $profile,
|
||||||
'profiler_url' => $url,
|
'templates' => $this->getTemplateManager()->getTemplates($profile),
|
||||||
'token' => $token,
|
'profiler_url' => $url,
|
||||||
)), 200, array('Content-Type' => 'text/html'));
|
'token' => $token,
|
||||||
|
)),
|
||||||
|
200,
|
||||||
|
array('Content-Type' => 'text/html')
|
||||||
|
)->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -241,15 +253,19 @@ class ProfilerController
|
|||||||
$token = $session->get('_profiler_search_token');
|
$token = $session->get('_profiler_search_token');
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Response($this->twig->render('@WebProfiler/Profiler/search.html.twig', array(
|
return Response::create(
|
||||||
'token' => $token,
|
$this->twig->render('@WebProfiler/Profiler/search.html.twig', array(
|
||||||
'ip' => $ip,
|
'token' => $token,
|
||||||
'method' => $method,
|
'ip' => $ip,
|
||||||
'url' => $url,
|
'method' => $method,
|
||||||
'start' => $start,
|
'url' => $url,
|
||||||
'end' => $end,
|
'start' => $start,
|
||||||
'limit' => $limit,
|
'end' => $end,
|
||||||
)), 200, array('Content-Type' => 'text/html'));
|
'limit' => $limit,
|
||||||
|
)),
|
||||||
|
200,
|
||||||
|
array('Content-Type' => 'text/html')
|
||||||
|
)->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -279,18 +295,22 @@ class ProfilerController
|
|||||||
$end = $request->query->get('end', null);
|
$end = $request->query->get('end', null);
|
||||||
$limit = $request->query->get('limit');
|
$limit = $request->query->get('limit');
|
||||||
|
|
||||||
return new Response($this->twig->render('@WebProfiler/Profiler/results.html.twig', array(
|
return Response::create(
|
||||||
'token' => $token,
|
$this->twig->render('@WebProfiler/Profiler/results.html.twig', array(
|
||||||
'profile' => $profile,
|
'token' => $token,
|
||||||
'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end),
|
'profile' => $profile,
|
||||||
'ip' => $ip,
|
'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end),
|
||||||
'method' => $method,
|
'ip' => $ip,
|
||||||
'url' => $url,
|
'method' => $method,
|
||||||
'start' => $start,
|
'url' => $url,
|
||||||
'end' => $end,
|
'start' => $start,
|
||||||
'limit' => $limit,
|
'end' => $end,
|
||||||
'panel' => null,
|
'limit' => $limit,
|
||||||
)), 200, array('Content-Type' => 'text/html'));
|
'panel' => null,
|
||||||
|
)),
|
||||||
|
200,
|
||||||
|
array('Content-Type' => 'text/html')
|
||||||
|
)->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -364,7 +384,7 @@ class ProfilerController
|
|||||||
phpinfo();
|
phpinfo();
|
||||||
$phpinfo = ob_get_clean();
|
$phpinfo = ob_get_clean();
|
||||||
|
|
||||||
return new Response($phpinfo, 200, array('Content-Type' => 'text/html'));
|
return Response::create($phpinfo, 200, array('Content-Type' => 'text/html'))->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -68,10 +68,14 @@ class RouterController
|
|||||||
|
|
||||||
$request = $profile->getCollector('request');
|
$request = $profile->getCollector('request');
|
||||||
|
|
||||||
return new Response($this->twig->render('@WebProfiler/Router/panel.html.twig', array(
|
return Response::create(
|
||||||
'request' => $request,
|
$this->twig->render('@WebProfiler/Router/panel.html.twig', array(
|
||||||
'router' => $profile->getCollector('router'),
|
'request' => $request,
|
||||||
'traces' => $matcher->getTraces($request->getPathInfo()),
|
'router' => $profile->getCollector('router'),
|
||||||
)), 200, array('Content-Type' => 'text/html'));
|
'traces' => $matcher->getTraces($request->getPathInfo()),
|
||||||
|
)),
|
||||||
|
200,
|
||||||
|
array('Content-Type' => 'text/html')
|
||||||
|
)->setCharset('UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,6 +69,7 @@ class ProfilerControllerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$response = $controller->toolbarAction(Request::create('/_wdt/found'), 'found');
|
$response = $controller->toolbarAction(Request::create('/_wdt/found'), 'found');
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$this->assertEquals('UTF-8', $response->getCharset(), 'Request charset is explicitly set to UTF-8');
|
||||||
|
|
||||||
$response = $controller->toolbarAction(Request::create('/_wdt/notFound'), 'notFound');
|
$response = $controller->toolbarAction(Request::create('/_wdt/notFound'), 'notFound');
|
||||||
$this->assertEquals(404, $response->getStatusCode());
|
$this->assertEquals(404, $response->getStatusCode());
|
||||||
|
Reference in New Issue
Block a user