8000 [Debug] Do not quote numbers in stack trace · symfony/symfony@9cb6bcc · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cb6bcc

Browse files
committed
[Debug] Do not quote numbers in stack trace
1 parent 61e5ddc commit 9cb6bcc

File tree

5 files changed

+71
-41
lines changed

5 files changed

+71
-41
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ public function formatArgs($args)
9494
$formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
9595
} elseif ('string' === $item[0]) {
9696
$formattedValue = sprintf("'%s'", htmlspecialchars($item[1], ENT_QUOTES, $this->charset));
97+
} elseif ('integer' === $item[0] || 'float' === $item[0]) {
98+
$formattedValue = var_export($item[1], true);
9799
} elseif ('null' === $item[0]) {
98100
$formattedValue = '<em>null</em>';
99101
} elseif ('boolean' === $item[0]) {

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ private function formatArgs(array $args)
384384
$formattedValue = '<em>'.strtolower(var_export($item[1], true)).'</em>';
385385
} elseif ('resource' === $item[0]) {
386386
$formattedValue = '<em>resource</em>';
387+
} elseif ('integer' === $item[0] || 'float' === $item[0]) {
388+
$formattedValue = var_export($item[1], true);
387389
} else {
388390
$formattedValue = str_replace("\n", '', var_export($this->escapeHtml((string) $item[1]), true));
389391
}

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