Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 374b718

Browse filesBrowse files
committed
bug #13901 [Bundle] Fix charset config (nicolas-grekas, bamarni)
This PR was merged into the 2.3 branch. Discussion ---------- [Bundle] Fix charset config | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #13715, #7617, #7532 | License | MIT | Doc PR | - This reverts #13715 and resurrects #7532, which was fine. Commits ------- ef41059 [WebProfilerBundle] Set debug+charset on the ExceptionHandler fallback cbd0525 used HTML5 meta charset tag and removed hardcoded ones 6ca7fc9 Revert "bug #13715 Enforce UTF-8 charset for core controllers (WouterJ)"
2 parents a4d6be4 + ef41059 commit 374b718
Copy full SHA for 374b718

File tree

Expand file treeCollapse file tree

10 files changed

+65
-95
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+65
-95
lines changed

‎src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Resources/views/base.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/Resources/views/base.html.twig
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="UTF-8" />
4+
<meta charset="{{ _charset }}" />
55
<title>{% block title %}Welcome!{% endblock %}</title>
66
{% block stylesheets %}{% endblock %}
77
<link rel="shortcut icon" href="{{ asset('favicon.ico') }}" />

‎src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function showAction(Request $request, FlattenException $exception, DebugL
5151

5252
$code = $exception->getStatusCode();
5353

54-
return Response::create($this->twig->render(
54+
return new Response($this->twig->render(
5555
(string) $this->findTemplate($request, $request->getRequestFormat(), $code, $this->debug),
5656
array(
5757
'status_code' => $code,
@@ -60,7 +60,7 @@ public function showAction(Request $request, FlattenException $exception, DebugL
6060
'logger' => $logger,
6161
'currentContent' => $currentContent,
6262
)
63-
))->setCharset('UTF-8');
63+
));
6464
}
6565

6666
/**

‎src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Resources/views/Exception/error.html.twig
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="UTF-8" />
4+
<meta charset="{{ _charset }}" />
55
<title>An Error Occurred: {{ status_text }}</title>
66
</head>
77
<body>

‎src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/TwigBundle/Tests/Controller/ExceptionControllerTest.php
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function testOnlyClearOwnOutputBuffers()
3939
$request->headers->set('X-Php-Ob-Level', 1);
4040

4141
$controller = new ExceptionController($twig, false);
42-
$response = $controller->showAction($request, $flatten);
43-
$this->assertEquals('UTF-8', $response->getCharset(), 'Request charset is explicitly set to UTF-8');
42+
$controller->showAction($request, $flatten);
4443
}
4544
}

‎src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php
+9-14Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,24 +55,23 @@ public function showAction($token)
5555
$template = $this->getTemplate();
5656

5757
if (!$this->twig->getLoader()->exists($template)) {
58-
$handler = new ExceptionHandler();
58+
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset());
5959

6060
return new Response($handler->getContent($exception), 200, array('Content-Type' => 'text/html'));
6161
}
6262

6363
$code = $exception->getStatusCode();
6464

65-
return Response::create(
66-
$this->twig->render($template, array(
65+
return new Response($this->twig->render(
66+
$template,
67+
array(
6768
'status_code' => $code,
6869
'status_text' => Response::$statusTexts[$code],
6970
'exception' => $exception,
7071
'logger' => null,
7172
'currentContent' => '',
72-
)),
73-
200,
74-
array('Content-Type' => 'text/html')
75-
)->setCharset('UTF-8');
73+
)
74+
), 200, array('Content-Type' => 'text/html'));
7675
}
7776

7877
/**
@@ -96,16 +95,12 @@ public function cssAction($token)
9695
$template = $this->getTemplate();
9796

9897
if (!$this->templateExists($template)) {
99-
$handler = new ExceptionHandler();
98+
$handler = new ExceptionHandler($this->debug, $this->twig->getCharset());
10099

101-
$response = new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css'));
102-
} else {
103-
$response = new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, array('Content-Type' => 'text/css'));
100+
return new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css'));
104101
}
105102

106-
$response->setCharset('UTF-8');
107-
108-
return $response;
103+
return new Response($this->twig->render('@WebProfiler/Collector/exception.css.twig'), 200, array('Content-Type' => 'text/css'));
109104
}
110105

111106
protected function getTemplate()

‎src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php
+42-62Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,16 @@ public function panelAction(Request $request, $token)
9999
throw new NotFoundHttpException(sprintf('Panel "%s" is not available for token "%s".', $panel, $token));
100100
}
101101

102-
return Response::create(
103-
$this->twig->render($this->getTemplateManager()->getName($profile, $panel), array(
104-
'token' => $token,
105-
'profile' => $profile,
106-
'collector' => $profile->getCollector($panel),
107-
'panel' => $panel,
108-
'page' => $page,
109-
'request' => $request,
110-
'templates' => $this->getTemplateManager()->getTemplates($profile),
111-
'is_ajax' => $request->isXmlHttpRequest(),
112-
)),
113-
200,
114-
array('Content-Type' => 'text/html')
115-
)->setCharset('UTF-8');
102+
return new Response($this->twig->render($this->getTemplateManager()->getName($profile, $panel), array(
103+
'token' => $token,
104+
'profile' => $profile,
105+
'collector' => $profile->getCollector($panel),
106+
'panel' => $panel,
107+
'page' => $page,
108+
'request' => $request,
109+
'templates' => $this->getTemplateManager()->getTemplates($profile),
110+
'is_ajax' => $request->isXmlHttpRequest(),
111+
)), 200, array('Content-Type' => 'text/html'));
116112
}
117113

118114
/**
@@ -151,13 +147,9 @@ public function infoAction($about)
151147

152148
$this->profiler->disable();
153149

154-
return Response::create(
155-
$this->twig->render('@WebProfiler/Profiler/info.html.twig', array(
156-
'about' => $about,
157-
)),
158-
200,
159-
array('Content-Type' => 'text/html')
160-
)->setCharset('UTF-8');
150+
return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array(
151+
'about' => $about,
152+
)), 200, array('Content-Type' => 'text/html'));
161153
}
162154

163155
/**
@@ -205,17 +197,13 @@ public function toolbarAction(Request $request, $token)
205197
// the profiler is not enabled
206198
}
207199

208-
return Response::create(
209-
$this->twig->render('@WebProfiler/Profiler/toolbar.html.twig', array(
210-
'position' => $position,
211-
'profile' => $profile,
212-
'templates' => $this->getTemplateManager()->getTemplates($profile),
213-
'profiler_url' => $url,
214-
'token' => $token,
215-
)),
216-
200,
217-
array('Content-Type' => 'text/html')
218-
)->setCharset('UTF-8');
200+
return new Response($this->twig->render('@WebProfiler/Profiler/toolbar.html.twig', array(
201+
'position' => $position,
202+
'profile' => $profile,
203+
'templates' => $this->getTemplateManager()->getTemplates($profile),
204+
'profiler_url' => $url,
205+
'token' => $token,
206+
)), 200, array('Content-Type' => 'text/html'));
219207
}
220208

221209
/**
@@ -253,19 +241,15 @@ public function searchBarAction(Request $request)
253241
$token = $session->get('_profiler_search_token');
254242
}
255243

256-
return Response::create(
257-
$this->twig->render('@WebProfiler/Profiler/search.html.twig', array(
258-
'token' => $token,
259-
'ip' => $ip,
260-
'method' => $method,
261-
'url' => $url,
262-
'start' => $start,
263-
'end' => $end,
264-
'limit' => $limit,
265-
)),
266-
200,
267-
array('Content-Type' => 'text/html')
268-
)->setCharset('UTF-8');
244+
return new Response($this->twig->render('@WebProfiler/Profiler/search.html.twig', array(
245+
'token' => $token,
246+
'ip' => $ip,
247+
'method' => $method,
248+
'url' => $url,
249+
'start' => $start,
250+
'end' => $end,
251+
'limit' => $limit,
252+
)), 200, array('Content-Type' => 'text/html'));
269253
}
270254

271255
/**
@@ -295,22 +279,18 @@ public function searchResultsAction(Request $request, $token)
295279
$end = $request->query->get('end', null);
296280
$limit = $request->query->get('limit');
297281

298-
return Response::create(
299-
$this->twig->render('@WebProfiler/Profiler/results.html.twig', array(
300-
'token' => $token,
301-
'profile' => $profile,
302-
'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end),
303-
'ip' => $ip,
304-
'method' => $method,
305-
'url' => $url,
306-
'start' => $start,
307-
'end' => $end,
308-
'limit' => $limit,
309-
'panel' => null,
310-
)),
311-
200,
312-
array('Content-Type' => 'text/html')
313-
)->setCharset('UTF-8');
282+
return new Response($this->twig->render('@WebProfiler/Profiler/results.html.twig', array(
283+
'token' => $token,
284+
'profile' => $profile,
285+
'tokens' => $this->profiler->find($ip, $url, $limit, $method, $start, $end),
286+
'ip' => $ip,
287+
'method' => $method,
288+
'url' => $url,
289+
'start' => $start,
290+
'end' => $end,
291+
'limit' => $limit,
292+
'panel' => null,
293+
)), 200, array('Content-Type' => 'text/html'));
314294
}
315295

316296
/**
@@ -384,7 +364,7 @@ public function phpinfoAction()
384364
phpinfo();
385365
$phpinfo = ob_get_clean();
386366

387-
return Response::create($phpinfo, 200, array('Content-Type' => 'text/html'))->setCharset('UTF-8');
367+
return new Response($phpinfo, 200, array('Content-Type' => 'text/html'));
388368
}
389369

390370
/**

‎src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Controller/RouterController.php
+5-9Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,10 @@ public function panelAction($token)
6868

6969
$request = $profile->getCollector('request');
7070

71-
return Response::create(
72-
$this->twig->render('@WebProfiler/Router/panel.html.twig', array(
73-
'request' => $request,
74-
'router' => $profile->getCollector('router'),
75-
'traces' => $matcher->getTraces($request->getPathInfo()),
76-
)),
77-
200,
78-
array('Content-Type' => 'text/html')
79-
)->setCharset('UTF-8');
71+
return new Response($this->twig->render('@WebProfiler/Router/panel.html.twig', array(
72+
'request' => $request,
73+
'router' => $profile->getCollector('router'),
74+
'traces' => $matcher->getTraces($request->getPathInfo()),
75+
)), 200, array('Content-Type' => 'text/html'));
8076
}
8177
}

‎src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base.html.twig

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/base.html.twig
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="UTF-8">
5-
<meta name="robots" content="noindex,nofollow">
4+
<meta charset="{{ _charset }}" />
5+
<meta name="robots" content="noindex,nofollow" />
66
<title>{% block title 'Profiler' %}</title>
77
<link rel="icon" type="image/x-icon" sizes="16x16" href="data:image/ico;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAQAABMLAAATCwAAAAAAAAAAAAAAAAAAAAAAADIvMQAyLzEIMi8xSzEuMKoyLzHkMi8x/TIvMf0yLzHlMi8xrDIvMU4yLzEJMi8xAAAAAAAAAAAAAAAAADIvMQAyLzEYMS4wkTMwMu45Njj/MS4w/zEuMP8yLzH/Mi8x/zIvMf8yLzHvMi8xlDIvMRkyLzEAAAAAADIvMQAyLzEXMS4wrTk2OP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DIvMY0yLzHqMi8x/zIvMf8yLzH/Mi8x/zIvMf8yLzH/MS4w7DEuMJEyLzEaMi8xAAAAAAAAAAAAAAAAADIvMQAyLzEGMi8xQzIvMZ4yLzHdMi8x+jIvMfoyLzHeMi8xoDIvMUUyLzEGMi8xAAAAAAAAAAAA4AcAAMADAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIABAADAAwAA4AcAAA==">
88
<style>

‎src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public function testReturns404onTokenNotFound()
6969

7070
$response = $controller->toolbarAction(Request::create('/_wdt/found'), 'found');
7171
$this->assertEquals(200, $response->getStatusCode());
72-
$this->assertEquals('UTF-8', $response->getCharset(), 'Request charset is explicitly set to UTF-8');
7372

7473
$response = $controller->toolbarAction(Request::create('/_wdt/notFound'), 'notFound');
7574
$this->assertEquals(404, $response->getStatusCode());

‎src/Symfony/Component/Debug/ExceptionHandler.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Debug/ExceptionHandler.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public function sendPhpResponse($exception)
9292
foreach ($exception->getHeaders() as $name => $value) {
9393
header($name.': '.$value, false);
9494
}
95+
header('Content-Type: text/html; charset='.$this->charset);
9596
}
9697

9798
echo $this->decorate($this->getContent($exception), $this->getStylesheet($exception));
@@ -110,7 +111,7 @@ public function createResponse($exception)
110111
$exception = FlattenException::create($exception);
111112
}
112113

113-
return new Response($this->decorate($this->getContent($exception), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders());
114+
return Response::create($this->decorate($this->getContent($exception), $this->getStylesheet($exception)), $exception->getStatusCode(), $exception->getHeaders())->setCharset($this->charset);
114115
}
115116

116117
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.