mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 20:34:47 +01:00
Merge pull request #7309 from orklah/emptyStringKeyedArray
fix empty string not quoted in keyed array offset
This commit is contained in:
commit
18ab5a099f
@ -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)) . '\'';
|
||||
}
|
||||
|
||||
|
@ -1944,6 +1944,33 @@ 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
|
||||
* @param mixed $actual
|
||||
* @psalm-assert =T $actual
|
||||
*/
|
||||
public function assertSame($expected, $actual): void
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user