Skip to content

Commit

Permalink
Merge pull request #7791 from ohader/issue-7771-4x
Browse files Browse the repository at this point in the history
Avoid json_encode when serializing non-UTF8 literals
  • Loading branch information
orklah committed Mar 16, 2022
2 parents ebffd52 + 9e4e468 commit 80f972c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Psalm/Internal/Clause.php
Expand Up @@ -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;
Expand Down Expand Up @@ -110,7 +110,7 @@ public function __construct(
sort($possibilities[$i]);
}

$this->hash = md5((string) json_encode($possibilities));
$this->hash = md5(serialize($possibilities));
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/TypeReconciliation/ConditionalTest.php
Expand Up @@ -2839,6 +2839,15 @@ function b(B $_b): void {
echo "false";
}',
],
'#7771: non-UTF8 binary data is passed' => [
'<?php
function matches(string $value): bool {
if ("\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1" !== $value) {
return false;
}
return true;
}'
],
];
}

Expand Down

0 comments on commit 80f972c

Please sign in to comment.