1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

scientific and underscore notation should be quoted too, since they won't be type juggled

This commit is contained in:
kkmuffme 2024-03-23 01:01:51 +01:00
parent cd302f040b
commit 1bfa684d7f
2 changed files with 12 additions and 0 deletions

View File

@ -720,11 +720,19 @@ class TKeyedArray extends Atomic
$quote = true;
}
if (preg_match('/^[1-9][0-9]*_([0-9]+_)*[0-9]+$/', $name)) {
$quote = true;
}
// 08 should be quoted since it's numeric but it's handled as string and not cast to int
if (preg_match('/^0[0-9]+$/', $name)) {
$quote = true;
}
if (preg_match('/^[0-9]+e-?[0-9]+$/', $name)) {
$quote = true;
}
if ($quote) {
$name = '\'' . str_replace("\n", '\n', addslashes($name)) . '\'';
}

View File

@ -193,6 +193,8 @@ class ArrayKeysTest extends TestCase
// see https://github.com/php/php-src/issues/9029#issuecomment-1186226676
$e = ["+15" => "a"];
$f = ["015" => "a"];
$g = ["1e2" => "a"];
$h = ["1_0" => "a"];
',
'assertions' => [
'$a===' => "array{15: 'a'}",
@ -201,6 +203,8 @@ class ArrayKeysTest extends TestCase
'$d===' => "array{-15: 'a'}",
'$e===' => "array{'+15': 'a'}",
'$f===' => "array{'015': 'a'}",
'$g===' => "array{'1e2': 'a'}",
'$h===' => "array{'1_0': 'a'}",
],
],
];