Skip to content

Commit 0ea9d96

Browse files
committed
Merge branch '5.4' into 6.3
* 5.4: Fix bad merge CS fix [ErrorHandler] Don't format binary strings [Validator] Consistently use "This value is not" instead of "This is not" in error messages [Messenger] Improve Redis integration tests [Validator] added missing Estonian and Romanian translations
2 parents 1f69476 + 0e58bb2 commit 0ea9d96

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

ErrorRenderer/HtmlErrorRenderer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ private function formatArgs(array $args): string
171171
$formattedValue = '<em>'.strtolower(var_export($item[1], true)).'</em>';
172172
} elseif ('resource' === $item[0]) {
173173
$formattedValue = '<em>resource</em>';
174+
} elseif (preg_match('/[^\x07-\x0D\x1B\x20-\xFF]/', $item[1])) {
175+
$formattedValue = '<em>binary string</em>';
174176
} else {
175177
$formattedValue = str_replace("\n", '', $this->escape(var_export($item[1], true)));
176178
}

Tests/ErrorRenderer/HtmlErrorRendererTest.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,45 @@ public static function getRenderData(): iterable
5454
$expectedNonDebug,
5555
];
5656
}
57+
58+
public function testRendersStackWithoutBinaryStrings()
59+
{
60+
if (\PHP_VERSION_ID >= 70400) {
61+
// make sure method arguments are available in stack traces (see https://www.php.net/manual/en/ini.core.php)
62+
ini_set('zend.exception_ignore_args', false);
63+
}
64+
65+
$binaryData = file_get_contents(__DIR__.'/../Fixtures/pixel.png');
66+
$exception = $this->getRuntimeException($binaryData);
67+
68+
$rendered = (new HtmlErrorRenderer(true))->render($exception)->getAsString();
69+
70+
$this->assertStringContainsString(
71+
"buildRuntimeException('FooException')",
72+
$rendered,
73+
'->render() contains the method call with "FooException"'
74+
);
75+
76+
$this->assertStringContainsString(
77+
'getRuntimeException(binary string)',
78+
$rendered,
79+
'->render() contains the method call with "binary string" replacement'
80+
);
81+
82+
$this->assertStringContainsString(
83+
'<em>binary string</em>',
84+
$rendered,
85+
'->render() returns the HTML content with "binary string" replacement'
86+
);
87+
}
88+
89+
private function getRuntimeException(string $unusedArgument): \RuntimeException
90+
{
91+
return $this->buildRuntimeException('FooException');
92+
}
93+
94+
private function buildRuntimeException(string $message): \RuntimeException
95+
{
96+
return new \RuntimeException($message);
97+
}
5798
}

Tests/Fixtures/pixel.png

69 Bytes
Loading

0 commit comments

Comments
 (0)