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 463b24b

Browse filesBrowse files
committed
bug #13715 Enforce UTF-8 charset for core controllers (WouterJ)
This PR was merged into the 2.3 branch. Discussion ---------- Enforce UTF-8 charset for core controllers | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7532 | License | MIT | Doc PR | - See #7617 and #7532 for the context of this PR. Commits ------- 3032014 Enforce UTF-8 charset for core controllers
2 parents c475704 + 3032014 commit 463b24b
Copy full SHA for 463b24b

File tree

Expand file treeCollapse file tree

6 files changed

+88
-57
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+88
-57
lines changed

‎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 new Response($this->twig->render(
54+
return Response::create($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-
));
63+
))->setCharset('UTF-8');
6464
}
6565

6666
/**

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

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

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

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Controller/ExceptionController.php
+12-7Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,17 @@ public function showAction($token)
6262

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

65-
return new Response($this->twig->render(
66-
$template,
67-
array(
65+
return Response::create(
66+
$this->twig->render($template, array(
6867
'status_code' => $code,
6968
'status_text' => Response::$statusTexts[$code],
7069
'exception' => $exception,
7170
'logger' => null,
7271
'currentContent' => '',
73-
)
74-
), 200, array('Content-Type' => 'text/html'));
72+
)),
73+
200,
74+
array('Content-Type' => 'text/html')
75+
)->setCharset('UTF-8');
7576
}
7677

7778
/**
@@ -97,10 +98,14 @@ public function cssAction($token)
9798
if (!$this->templateExists($template)) {
9899
$handler = new ExceptionHandler();
99100

100-
return new Response($handler->getStylesheet($exception), 200, array('Content-Type' => 'text/css'));
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'));
101104
}
102105

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

106111
protected function getTemplate()

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

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php
+62-42Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,20 @@ 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 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'));
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');
112116
}
113117

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

148152
$this->profiler->disable();
149153

150-
return new Response($this->twig->render('@WebProfiler/Profiler/info.html.twig', array(
151-
'about' => $about,
152-
)), 200, array('Content-Type' => 'text/html'));
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');
153161
}
154162

155163
/**
@@ -197,13 +205,17 @@ public function toolbarAction(Request $request, $token)
197205
// the profiler is not enabled
198206
}
199207

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'));
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');
207219
}
208220

209221
/**
@@ -241,15 +253,19 @@ public function searchBarAction(Request $request)
241253
$token = $session->get('_profiler_search_token');
242254
}
243255

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'));
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');
253269
}
254270

255271
/**
@@ -279,18 +295,22 @@ public function searchResultsAction(Request $request, $token)
279295
$end = $request->query->get('end', null);
280296
$limit = $request->query->get('limit');
281297

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'));
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');
294314
}
295315

296316
/**
@@ -364,7 +384,7 @@ public function phpinfoAction()
364384
phpinfo();
365385
$phpinfo = ob_get_clean();
366386

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

370390
/**

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

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

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

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'));
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');
7680
}
7781
}

‎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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ 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');
7273

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

0 commit comments

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