1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

fix empty string in keyed array offset

This commit is contained in:
orklah 2022-01-05 22:26:35 +01:00
parent e41fc678d3
commit 7e2b9d0fab
2 changed files with 27 additions and 1 deletions

View File

@ -430,7 +430,7 @@ class TKeyedArray extends Atomic
*/
private function escapeAndQuote($name)
{
if (is_string($name) && preg_match('/[^a-zA-Z0-9_]/', $name)) {
if (is_string($name) && ($name === '' || preg_match('/[^a-zA-Z0-9_]/', $name))) {
$name = '\'' . str_replace("\n", '\n', addslashes($name)) . '\'';
}

View File

@ -1921,6 +1921,32 @@ class AssertAnnotationTest extends TestCase
function requiresString(string $_str): void {}
',
],
'assertWithEmptyStringOnKeyedArray' => [
'<?php
class A
{
function test(): void
{
$a = ["" => ""];
/** @var array<string, mixed> $b */
$b = [];
$this->assertSame($a, $b);
}
/**
* @template T
* @param T $expected
* @psalm-assert =T $actual
*/
public function assertSame(mixed $expected, mixed $actual): void
{
return;
}
}
',
],
];
}