Skip to content

Commit

Permalink
[HttpKernel] fixed recursion when flattenning an exception stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jul 7, 2011
1 parent 2ec4b04 commit 76a5816
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Expand Up @@ -169,14 +169,18 @@ public function setTrace($trace, $file, $line)
}
}

private function flattenArgs($args)
private function flattenArgs($args, $level = 0)
{
$result = array();
foreach ($args as $key => $value) {
if (is_object($value)) {
$result[$key] = array('object', get_class($value));
} elseif (is_array($value)) {
$result[$key] = array('array', $this->flattenArgs($value));
if ($level > 100) {
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
} else {
$result[$key] = array('array', $this->flattenArgs($value, ++$level));
}
} elseif (null === $value) {
$result[$key] = array('null', null);
} elseif (is_bool($value)) {
Expand Down
Expand Up @@ -71,4 +71,19 @@ public function flattenDataProvider()
array(new \Exception('test', 123), 500),
);
}

public function testRecursionInArguments()
{
$a = array('foo', array(2, &$a));
$exception = $this->createException($a);

$flattened = FlattenException::create($exception);
$trace = $flattened->getTrace();
$this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
}

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

2 comments on commit 76a5816

@olegstepura
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100 is a lot. It should be reduced and maybe 10 will be just enough

@olegstepura
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually I don't understand why ExceptionHandler uses FlattenException as it doesn't output any context.

Please sign in to comment.