From b00d9e9514552d5fa2f359302c94d9d0b71745e7 Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Tue, 15 Mar 2022 03:12:14 +0100 Subject: [PATCH 1/3] Add test case reproducing issue #7771 Related: #7771 --- tests/TypeReconciliation/ConditionalTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/TypeReconciliation/ConditionalTest.php b/tests/TypeReconciliation/ConditionalTest.php index 670c3bb138f..1faec5c42db 100644 --- a/tests/TypeReconciliation/ConditionalTest.php +++ b/tests/TypeReconciliation/ConditionalTest.php @@ -2839,6 +2839,15 @@ function b(B $_b): void { echo "false"; }', ], + 'BinaryDataIsPassedSeeIssue7771' => [ + 'code' => ' Date: Tue, 15 Mar 2022 10:39:58 +0100 Subject: [PATCH 2/3] Avoid json_encode when serializing non-UTF8 literals `\Psalm\Internal\Clause::$hash` basically holds a hash on arbitrary input literals, used for later comparison. Using `json_encode` fails when dealing with non-UTF8 literals, which has been replaced by plain PHP `serialize`. Resolves: #7771 --- src/Psalm/Internal/Clause.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Psalm/Internal/Clause.php b/src/Psalm/Internal/Clause.php index 5497f579b9b..f861487c2cf 100644 --- a/src/Psalm/Internal/Clause.php +++ b/src/Psalm/Internal/Clause.php @@ -11,10 +11,10 @@ use function array_values; use function count; use function implode; -use function json_encode; use function ksort; use function md5; use function reset; +use function serialize; use function sort; use function strpos; use function substr; @@ -110,7 +110,7 @@ public function __construct( sort($possibilities[$i]); } - $this->hash = md5((string) json_encode($possibilities)); + $this->hash = md5(serialize($possibilities)); } } From 9e4e468907be1575fe1aa262bd51b49456da92bd Mon Sep 17 00:00:00 2001 From: Oliver Hader Date: Wed, 16 Mar 2022 10:35:11 +0100 Subject: [PATCH 3/3] Adjust test case format Related: #7771 --- tests/TypeReconciliation/ConditionalTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/TypeReconciliation/ConditionalTest.php b/tests/TypeReconciliation/ConditionalTest.php index 1faec5c42db..ac5ee27f322 100644 --- a/tests/TypeReconciliation/ConditionalTest.php +++ b/tests/TypeReconciliation/ConditionalTest.php @@ -2839,8 +2839,8 @@ function b(B $_b): void { echo "false"; }', ], - 'BinaryDataIsPassedSeeIssue7771' => [ - 'code' => ' [ + '