Skip to content

Commit 8b3ab22

Browse files
committed
Fix implicit conversion from float to int in AlterOperation
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent 3d0c3a6 commit 8b3ab22

File tree

6 files changed

+120
-13
lines changed

6 files changed

+120
-13
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ parameters:
1515
count: 1
1616
path: src/Components/AlterOperation.php
1717

18-
-
19-
message: "#^Parameter \\#1 \\$key of function array_key_exists expects int\\|string, float\\|int\\|string given\\.$#"
20-
count: 2
21-
path: src/Components/AlterOperation.php
22-
2318
-
2419
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\AlterOperation\\:\\:\\$options \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
2520
count: 1

psalm-baseline.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
<InvalidScalarArgument occurrences="1">
1313
<code>$arrayKey</code>
1414
</InvalidScalarArgument>
15-
<MixedArrayOffset occurrences="1">
16-
<code>Parser::$STATEMENT_PARSERS[$token-&gt;value]</code>
17-
</MixedArrayOffset>
1815
<MoreSpecificImplementedParamType occurrences="1">
1916
<code>$component</code>
2017
</MoreSpecificImplementedParamType>
@@ -631,8 +628,7 @@
631628
<code>$this-&gt;last</code>
632629
<code>$this-&gt;last</code>
633630
</LoopInvalidation>
634-
<MixedArrayAccess occurrences="42">
635-
<code>$this-&gt;str[$this-&gt;last + 1]</code>
631+
<MixedArrayAccess occurrences="41">
636632
<code>$this-&gt;str[$this-&gt;last + 1]</code>
637633
<code>$this-&gt;str[$this-&gt;last++]</code>
638634
<code>$this-&gt;str[$this-&gt;last]</code>

src/Components/AlterOperation.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
use function array_key_exists;
1313
use function in_array;
14-
use function is_numeric;
14+
use function is_int;
1515
use function is_string;
1616
use function trim;
1717

@@ -412,7 +412,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
412412

413413
$state = 2;
414414
} elseif ($state === 2) {
415-
if (is_string($token->value) || is_numeric($token->value)) {
415+
if (is_string($token->value) || is_int($token->value)) {
416416
$arrayKey = $token->value;
417417
} else {
418418
$arrayKey = $token->token;
@@ -445,7 +445,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
445445
);
446446
break;
447447
}
448-
} elseif (! empty(Parser::$STATEMENT_PARSERS[$token->value])) {
448+
} elseif (! empty(Parser::$STATEMENT_PARSERS[$arrayKey])) {
449449
// We have reached the end of ALTER operation and suddenly found
450450
// a start to new statement, but have not found a delimiter between them
451451
$parser->error(

tests/Misc/BugsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function testBug(string $test): void
2222
public function bugProvider(): array
2323
{
2424
return [
25+
['bugs/fuzz1'],
2526
['bugs/gh9'],
2627
['bugs/gh14'],
2728
['bugs/gh16'],

tests/data/bugs/fuzz1.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER..2

tests/data/bugs/fuzz1.out

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"query": "ALTER..2",
3+
"lexer": {
4+
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
5+
"str": "ALTER..2",
6+
"len": 8,
7+
"last": 8,
8+
"list": {
9+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
10+
"tokens": [
11+
{
12+
"@type": "PhpMyAdmin\\SqlParser\\Token",
13+
"token": "ALTER",
14+
"value": "ALTER",
15+
"keyword": "ALTER",
16+
"type": 1,
17+
"flags": 3,
18+
"position": 0
19+
},
20+
{
21+
"@type": "PhpMyAdmin\\SqlParser\\Token",
22+
"token": ".",
23+
"value": ".",
24+
"keyword": null,
25+
"type": 2,
26+
"flags": 16,
27+
"position": 5
28+
},
29+
{
30+
"@type": "PhpMyAdmin\\SqlParser\\Token",
31+
"token": ".2",
32+
"value": 0.2,
33+
"keyword": null,
34+
"type": 6,
35+
"flags": 2,
36+
"position": 6
37+
},
38+
{
39+
"@type": "PhpMyAdmin\\SqlParser\\Token",
40+
"token": null,
41+
"value": null,
42+
"keyword": null,
43+
"type": 9,
44+
"flags": 0,
45+
"position": null
46+
}
47+
],
48+
"count": 4,
49+
"idx": 4
50+
},
51+
"delimiter": ";",
52+
"delimiterLen": 1,
53+
"strict": false,
54+
"errors": []
55+
},
56+
"parser": {
57+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
58+
"list": {
59+
"@type": "@1"
60+
},
61+
"statements": [
62+
{
63+
"@type": "PhpMyAdmin\\SqlParser\\Statements\\AlterStatement",
64+
"table": {
65+
"@type": "PhpMyAdmin\\SqlParser\\Components\\Expression",
66+
"database": null,
67+
"table": null,
68+
"column": null,
69+
"expr": ".",
70+
"alias": null,
71+
"function": null,
72+
"subquery": null
73+
},
74+
"altered": [
75+
{
76+
"@type": "PhpMyAdmin\\SqlParser\\Components\\AlterOperation",
77+
"options": {
78+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
79+
"options": []
80+
},
81+
"field": null,
82+
"partitions": null,
83+
"unknown": [
84+
{
85+
"@type": "@4"
86+
}
87+
]
88+
}
89+
],
90+
"options": {
91+
"@type": "PhpMyAdmin\\SqlParser\\Components\\OptionsArray",
92+
"options": []
93+
},
94+
"first": 0,
95+
"last": 3
96+
}
97+
],
98+
"brackets": 0,
99+
"strict": false,
100+
"errors": []
101+
},
102+
"errors": {
103+
"lexer": [],
104+
"parser": [
105+
[
106+
"Unrecognized alter operation.",
107+
{
108+
"@type": "@5"
109+
},
110+
0
111+
]
112+
]
113+
}
114+
}

0 commit comments

Comments
 (0)