8000 feature #19079 [Debug] Do not quote numbers in stack trace (c960657) · symfony/symfony@414a4b4 · GitHub
[go: up one dir, main page]

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 414a4b4

Browse files
committed
feature #19079 [Debug] Do not quote numbers in stack trace (c960657)
This PR was merged into the 3.2-dev branch. Discussion ---------- [Debug] Do not quote numbers in stack trace | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | In the debug output from the exception handler, integers and floats are quoted. This adds unnecessary noise to the error page and is just wrong. Fixing this requires introduces two new type descriptions in the output from getTrace(), so the change is not fully backwards compatible. Commits ------- fb10b33 [Debug] Do not quote numbers in stack trace
2 parents afed2f8 + fb10b33 commit 414a4b4

File tree

6 files changed

+77
-48
lines changed

6 files changed

+77
-48
lines changed

UPGRADE-4.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
UPGRADE FROM 3.x to 4.0
22
=======================
33

4+
Debug
5+
-----
6+
7+
* `FlattenException::getTrace()` now returns additional type descriptions
8+
`integer` and `float`.
9+
410
DependencyInjection
511
-------------------
612

src/Symfony/Bridge/Twig/Extension/CodeExtension.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,14 @@ public function formatArgs($args)
9292
$formattedValue = sprintf('<em>object</em>(<abbr title="%s">%s</abbr>)', $item[1], $short);
9393
} elseif ('array' === $item[0]) {
9494
$formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
95-
} elseif ('string' === $item[0]) {
96-
$formattedValue = sprintf("'%s'", htmlspecialchars($item[1], ENT_QUOTES, $this->charset));
9795
} elseif ('null' === $item[0]) {
9896
$formattedValue = '<em>null</em>';
9997
} elseif ('boolean' === $item[0]) {
10098
$formattedValue = '<em>'.strtolower(var_export($item[1], true)).'</em>';
10199
} elseif ('resource' === $item[0]) {
102100
$formattedValue = '<em>resource</em>';
103101
} else {
104-
$formattedValue = str_replace("\n", '', var_export(htmlspecialchars((string) $item[1], ENT_QUOTES, $this->charset), true));
102+
$formattedValue = str_replace("\n", '', htmlspecialchars(var_export($item[1], true), ENT_COMPAT | ENT_SUBSTITUTE, $this->charset));
105103
}
106104

107105
$result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $key, $formattedValue);
@@ -174,7 +172,7 @@ public function formatFile($file, $line, $text = null)
174172
$text = "$text at line $line";
175173

176174
if (false !== $link = $this->getFileLink($file, $line)) {
177-
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
175+
$flags = ENT_COMPAT | ENT_SUBSTITUTE;
178176

179177
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
180178
}

src/Symfony/Component/Debug/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
3.2.0
5+
-----
6+
7+
* `FlattenException::getTrace()` now returns additional type descriptions
8+
`integer` and `float`.
9+
10+
411
3.0.0
512
-----
613

src/Symfony/Component/Debug/Exception/FlattenException.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ private function flattenArgs($args, $level = 0, &$count = 0)
234234
$result[$key] = array('null', null);
235235
} elseif (is_bool($value)) {
236236
$result[$key] = array('boolean', $value);
237+
} elseif (is_integer($value)) {
238+
$result[$key] = array('integer', $value);
239+
} elseif (is_float($value)) {
240+
$result[$key] = array('float', $value);
237241
} elseif (is_resource($value)) {
238242
$result[$key] = array('resource', get_resource_type($value));
239243
} elseif ($value instanceof \__PHP_Incomplete_Class) {

src/Symfony/Component/Debug/ExceptionHandler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,14 @@ private function formatArgs(array $args)
376376
$formattedValue = sprintf('<em>object</em>(%s)', $this->formatClass($item[1]));
377377
} elseif ('array' === $item[0]) {
378378
$formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
379-
} elseif ('string' === $item[0]) {
380-
$formattedValue = sprintf("'%s'", $this->escapeHtml($item[1]));
381379
} elseif ('null' === $item[0]) {
382380
$formattedValue = '<em>null</em>';
383381
} elseif ('boolean' === $item[0]) {
384382
$formattedValue = '<em>'.strtolower(var_export($item[1], true)).'</em>';
385383
} elseif ('resource' === $item[0]) {
386384
$formattedValue = '<em>resource</em>';
387385
} else {
388-
$formattedValue = str_replace("\n", '', var_export($this->escapeHtml((string) $item[1]), true));
386+
$formattedValue = str_replace("\n", '', $this->escapeHtml(var_export($item[1], true)));
389387
}
390388

391389
$result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $key, $formattedValue);

src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php

Lines changed: 57 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,60 @@ public function flattenDataProvider()
190190
);
191191
}
192192

193+
public function testArguments()
194+
{
195+
$dh = opendir(__DIR__);
196+
197+
$incomplete = unserialize('O:14:"BogusTestClass":0:{}');
198+
199+
$exception = $this->createException(array(
200+
(object) array('foo' => 1),
201+
new NotFoundHttpException(),
202+
$incomplete,
203+
$dh,
204+
function() {},
205+
array(1, 2),
206+
array('foo' => 123),
207+
null,
208+
true,
209+
false,
210+
0,
211+
0.0,
212+
'0',
213+
'',
214+
INF,
215+
NAN,
216+
));
217+
218+
$flattened = FlattenException::create($exception);
219+
$trace = $flattened->getTrace();
220+
$args = $trace[1]['args'];
221+
$array = $args[0][1];
222+
223+
closedir($dh);
224+
225+
$i = 0;
226+
$this->assertSame($array[$i++], array('object', 'stdClass'));
227+
$this->assertSame($array[$i++], array('object', 'Symfony\Component\HttpKernel\Exception\NotFoundHttpException'));
228+
$this->assertSame($array[$i++], array('incomplete-object', 'BogusTestClass'));
229+
$this->assertSame($array[$i++], array('resource', 'stream'));
230+
$this->assertSame($array[$i++], array('object', 'Closure'));
231+
$this->assertSame($array[$i++], array('array', array(array('integer', 1), array('integer', 2))));
232+
$this->assertSame($array[$i++], array('array', array('foo' => array('integer', 123))));
233+
$this->assertSame($array[$i++], array('null', null));
234+
$this->assertSame($array[$i++], array('boolean', true));
235+
$this->assertSame($array[$i++], array('boolean', false));
236+
$this->assertSame($array[$i++], array('integer', 0));
237+
$this->assertSame($array[$i++], array('float', 0.0));
238+
$this->assertSame($array[$i++], array('string', '0'));
239+
$this->assertSame($array[$i++], array('string', ''));
240+
$this->assertSame($array[$i++], array('float', INF));
241+
242+
// assertEquals() does not like NAN values.
243+
$this->assertEquals($array[$i][0], 'float');
244+
$this->assertTrue(is_nan($array[$i++][1]));
245+
}
246+
193247
public function testRecursionInArguments()
194248
{
195249
$a = array('foo', array(2, &$a));
@@ -216,6 +270,9 @@ public function testTooBigArray()
216270

217271
$flattened = FlattenException::create($exception);
218272
$trace = $flattened->getTrace();
273+
274+
$this->assertSame($trace[1]['args'][0], array('array', array('array', '*SKIPPED over 10000 entries*')));
275+
219276
$serializeTrace = serialize($trace);
220277

221278
$this->assertContains('*SKIPPED over 10000 entries*', $serializeTrace);
@@ -226,45 +283,4 @@ private function createException($foo)
226283
{
227284
return new \Exception();
228285
}
229-
230-
public function testSetTraceIncompleteClass()
231-
{
232-
$flattened = FlattenException::create(new \Exception('test', 123));
233-
$flattened->setTrace(
234-
array(
235-
array(
236-
'file' => __FILE__,
237-
'line' => 123,
238-
'function' => 'test',
239-
'args' => array(
240-
unserialize('O:14:"BogusTestClass":0:{}'),
241-
),
242-
),
243-
),
244-
'foo.php', 123
245-
);
246-
247-
$this->assertEquals(array(
248-
array(
249-
'message' => 'test',
250-
'class' => 'Exception',
251-
'trace' => array(
252-
array(
253-
'namespace' => '', 'short_class' => '', 'class' => '', 'type' => '', 'function' => '',
254-
'file' => 'foo.php', 'line' => 123,
255-
'args' => array(),
256-
),
257-
array(
258-
'namespace' => '', 'short_class' => '', 'class' => '', 'type' => '', 'function' => 'test',
259-
'file' => __FILE__, 'line' => 123,
260-
'args' => array(
261-
array(
262-
'incomplete-object', 'BogusTestClass',
263-
),
264-
),
265-
),
266-
),
267-
),
268-
), $flattened->toArray());
269-
}
270286
}

0 commit comments

Comments
 (0)
0