Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add a limit and a test to FlattenExceptionTest.
  • Loading branch information
dawehner authored and fabpot committed Dec 17, 2014
1 parent 3a35bec commit c6bcf05
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Symfony/Component/Debug/Exception/FlattenException.php
Expand Up @@ -239,17 +239,20 @@ public function setTrace($trace, $file, $line)
}
}

private function flattenArgs($args, $level = 0)
private function flattenArgs($args, $level = 0, &$count = 0)
{
$result = array();
foreach ($args as $key => $value) {
if (++$count > 1e4) {
return array('array', '*SKIPPED over 10000 entries*');
}
if (is_object($value)) {
$result[$key] = array('object', get_class($value));
} elseif (is_array($value)) {
if ($level > 10) {
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
} else {
$result[$key] = array('array', $this->flattenArgs($value, $level + 1));
$result[$key] = array('array', $this->flattenArgs($value, $level + 1, $count));
}
} elseif (null === $value) {
$result[$key] = array('null', null);
Expand Down
Expand Up @@ -186,6 +186,28 @@ public function testRecursionInArguments()
$this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
}

public function testTooBigArray()
{
$a = array();
for ($i = 0; $i < 20; $i++) {
for ($j = 0; $j < 50; $j++) {
for ($k = 0; $k < 10; $k++) {
$a[$i][$j][$k] = 'value';
}
}
}
$a[20] = 'value';
$a[21] = 'value1';
$exception = $this->createException($a);

$flattened = FlattenException::create($exception);
$trace = $flattened->getTrace();
$serialize_trace = serialize($trace);

$this->assertContains('*SKIPPED over 10000 entries*', $serialize_trace);
$this->assertNotContains('*value1*', $serialize_trace);
}

private function createException($foo)
{
return new \Exception();
Expand Down

0 comments on commit c6bcf05

Please sign in to comment.