Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Symfony/Bridge/Twig/Extension/CodeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ public function formatArgs(array $args): string
$formattedValue = '<em>'.strtolower(htmlspecialchars(var_export($item[1], true), \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset)).'</em>';
} elseif ('resource' === $item[0]) {
$formattedValue = '<em>resource</em>';
} elseif (preg_match('/[^\x07-\x0D\x1B\x20-\xFF]/', $item[1])) {
$formattedValue = '<em>binary string</em>';
} else {
$formattedValue = str_replace("\n", '', htmlspecialchars(var_export($item[1], true), \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset));
$formattedValue = str_replace("\n", '', $this->escape(var_export($item[1], true)));
}

$result[] = \is_int($key) ? $formattedValue : sprintf("'%s' => %s", htmlspecialchars($key, \ENT_COMPAT | \ENT_SUBSTITUTE, $this->charset), $formattedValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ private function formatArgs(array $args): string
$formattedValue = '<em>'.strtolower(var_export($item[1], true)).'</em>';
} elseif ('resource' === $item[0]) {
$formattedValue = '<em>resource</em>';
} elseif (preg_match('/[^\x07-\x0D\x1B\x20-\xFF]/', $item[1])) {
$formattedValue = '<em>binary string</em>';
} else {
$formattedValue = str_replace("\n", '', $this->escape(var_export($item[1], true)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,45 @@ public static function getRenderData(): iterable
$expectedNonDebug,
];
}

public function testRendersStackWithoutBinaryStrings()
{
if (\PHP_VERSION_ID >= 70400) {
// make sure method arguments are available in stack traces (see https://www.php.net/manual/en/ini.core.php)
ini_set('zend.exception_ignore_args', false);
}

$binaryData = file_get_contents(__DIR__ . '/../Fixtures/pixel.png');
$exception = $this->getRuntimeException($binaryData);

$rendered = (new HtmlErrorRenderer(true))->render($exception)->getAsString();

$this->assertStringContainsString(
"buildRuntimeException('FooException')",
$rendered,
'->render() contains the method call with "FooException"'
);

$this->assertStringContainsString(
'getRuntimeException(binary string)',
$rendered,
'->render() contains the method call with "binary string" replacement'
);

$this->assertStringContainsString(
'<em>binary string</em>',
$rendered,
'->render() returns the HTML content with "binary string" replacement'
);
}

private function getRuntimeException(string $unusedArgument): \RuntimeException
{
return $this->buildRuntimeException('FooException');
}

private function buildRuntimeException(string $message): \RuntimeException
{
return new \RuntimeException($message);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.