Skip to content

Commit 6f769cf

Browse files
committed
Merge branch '5.9.x'
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
2 parents eccca02 + 445804d commit 6f769cf

23 files changed

+707
-56
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ parameters:
55
count: 3
66
path: src/Components/AlterOperation.php
77

8-
-
9-
message: "#^Parameter \\#1 \\$key of function array_key_exists expects int\\|string, float\\|int\\|string given\\.$#"
10-
count: 2
11-
path: src/Components/AlterOperation.php
12-
138
-
149
message: "#^Property PhpMyAdmin\\\\SqlParser\\\\Components\\\\AlterOperation\\:\\:\\$options \\(PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\) does not accept PhpMyAdmin\\\\SqlParser\\\\Components\\\\OptionsArray\\|null\\.$#"
1510
count: 1

psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
'DO' => 10,
3939
]]]></code>
4040
</InvalidPropertyAssignmentValue>
41-
<MixedArrayOffset>
42-
<code><![CDATA[Parser::$statementParsers[$token->value]]]></code>
43-
</MixedArrayOffset>
4441
<MoreSpecificImplementedParamType>
4542
<code>$component</code>
4643
</MoreSpecificImplementedParamType>

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

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

409409
$state = 2;
410410
} elseif ($state === 2) {
411-
if (is_string($token->value) || is_numeric($token->value)) {
411+
if (is_string($token->value) || is_int($token->value)) {
412412
$arrayKey = $token->value;
413413
} else {
414414
$arrayKey = $token->token;
@@ -441,7 +441,7 @@ public static function parse(Parser $parser, TokensList $list, array $options =
441441
);
442442
break;
443443
}
444-
} elseif (! empty(Parser::$statementParsers[$token->value])) {
444+
} elseif (! empty(Parser::$statementParsers[$arrayKey])) {
445445
// We have reached the end of ALTER operation and suddenly found
446446
// a start to new statement, but have not found a delimiter between them
447447
$parser->error(

src/Components/ArrayObj.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ public static function parse(Parser $parser, TokensList $list, array $options =
8989

9090
// End of statement.
9191
if ($token->type === Token::TYPE_DELIMITER) {
92+
if ($brackets > 0) {
93+
$parser->error('A closing bracket was expected.', $token);
94+
}
95+
9296
break;
9397
}
9498

src/Statements/AlterStatement.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ class AlterStatement extends Statement
6767
public function parse(Parser $parser, TokensList $list): void
6868
{
6969
++$list->idx; // Skipping `ALTER`.
70-
$this->options = OptionsArray::parse($parser, $list, static::$statementOptions);
70+
$parsedOptions = OptionsArray::parse($parser, $list, static::$statementOptions);
71+
if ($parsedOptions->isEmpty()) {
72+
$parser->error('Unrecognized alter operation.', $list->tokens[$list->idx]);
73+
74+
return;
75+
}
76+
77+
$this->options = $parsedOptions;
7178
++$list->idx;
7279

7380
// Parsing affected table.

src/Statements/WithStatement.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PhpMyAdmin\SqlParser\Translator;
1616

1717
use function array_slice;
18+
use function preg_match;
1819

1920
/**
2021
* `WITH` statement.
@@ -111,7 +112,7 @@ public function parse(Parser $parser, TokensList $list): void
111112
}
112113

113114
if ($state === 0) {
114-
if ($token->type !== Token::TYPE_NONE) {
115+
if ($token->type !== Token::TYPE_NONE || ! preg_match('/^[a-zA-Z0-9_$]+$/', $token->token)) {
115116
$parser->error('The name of the CTE was expected.', $token);
116117
break;
117118
}
@@ -121,7 +122,12 @@ public function parse(Parser $parser, TokensList $list): void
121122
$state = 1;
122123
} elseif ($state === 1) {
123124
if ($token->type === Token::TYPE_OPERATOR && $token->value === '(') {
124-
$this->withers[$wither]->columns = Array2d::parse($parser, $list);
125+
$columns = Array2d::parse($parser, $list);
126+
if ($parser->errors !== []) {
127+
break;
128+
}
129+
130+
$this->withers[$wither]->columns = $columns;
125131
$state = 2;
126132
} elseif ($token->type === Token::TYPE_KEYWORD && $token->keyword === 'AS') {
127133
$state = 3;

src/Token.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ public function extract(): mixed
251251
case self::TYPE_NUMBER:
252252
$ret = str_replace('--', '', $this->token); // e.g. ---42 === -42
253253
if ($this->flags & self::FLAG_NUMBER_HEX) {
254+
$ret = str_replace(['-', '+'], '', $this->token);
254255
if ($this->flags & self::FLAG_NUMBER_NEGATIVE) {
255-
$ret = str_replace('-', '', $this->token);
256256
$ret = -hexdec($ret);
257257
} else {
258258
$ret = hexdec($ret);

tests/Misc/BugsTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public function testBug(string $test): void
2121
public static function bugProvider(): array
2222
{
2323
return [
24+
['bugs/fuzz1'],
25+
['bugs/fuzz2'],
26+
['bugs/fuzz3'],
27+
['bugs/fuzz4'],
2428
['bugs/gh9'],
2529
['bugs/gh14'],
2630
['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: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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": null,
65+
"altered": [],
66+
"options": null,
67+
"first": 0,
68+
"last": 0
69+
}
70+
],
71+
"brackets": 0,
72+
"strict": false,
73+
"errors": []
74+
},
75+
"errors": {
76+
"lexer": [],
77+
"parser": [
78+
[
79+
"Unrecognized alter operation.",
80+
{
81+
"@type": "@2"
82+
},
83+
0
84+
],
85+
[
86+
"Unexpected beginning of statement.",
87+
{
88+
"@type": "@4"
89+
},
90+
0
91+
]
92+
]
93+
}
94+
}

0 commit comments

Comments
 (0)