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:
parent
e41fc678d3
commit
7e2b9d0fab
@ -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)) . '\'';
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user