Skip to content

Commit 796b135

Browse files
committed
Fix invalid hexadecimal prefix 0X
- Fixes #508 Signed-off-by: Maurício Meneghini Fauth <[email protected]>
1 parent c5a8c54 commit 796b135

File tree

6 files changed

+163
-95
lines changed

6 files changed

+163
-95
lines changed

src/Lexer.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -851,10 +851,7 @@ public function parseNumber()
851851
} elseif (
852852
$this->last + 1 < $this->len
853853
&& $this->str[$this->last] === '0'
854-
&& (
855-
$this->str[$this->last + 1] === 'x'
856-
|| $this->str[$this->last + 1] === 'X'
857-
)
854+
&& $this->str[$this->last + 1] === 'x'
858855
) {
859856
$token .= $this->str[$this->last++];
860857
$state = 2;

tests/Misc/BugsTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public function bugProvider(): array
2626
['bugs/gh14'],
2727
['bugs/gh16'],
2828
['bugs/gh317'],
29+
['bugs/gh508'],
2930
['bugs/pma11800'],
3031
['bugs/pma11836'],
3132
['bugs/pma11843'],

tests/data/bugs/gh508.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0X0F

tests/data/bugs/gh508.out

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"query": "0X0F",
3+
"lexer": {
4+
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
5+
"str": "0X0F",
6+
"len": 4,
7+
"last": 4,
8+
"list": {
9+
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
10+
"tokens": [
11+
{
12+
"@type": "PhpMyAdmin\\SqlParser\\Token",
13+
"token": "0X0F",
14+
"value": "0X0F",
15+
"keyword": null,
16+
"type": 0,
17+
"flags": 0,
18+
"position": 0
19+
},
20+
{
21+
"@type": "PhpMyAdmin\\SqlParser\\Token",
22+
"token": null,
23+
"value": null,
24+
"keyword": null,
25+
"type": 9,
26+
"flags": 0,
27+
"position": null
28+
}
29+
],
30+
"count": 2,
31+
"idx": 2
32+
},
33+
"delimiter": ";",
34+
"delimiterLen": 1,
35+
"strict": false,
36+
"errors": []
37+
},
38+
"parser": {
39+
"@type": "PhpMyAdmin\\SqlParser\\Parser",
40+
"list": {
41+
"@type": "@1"
42+
},
43+
"statements": [],
44+
"brackets": 0,
45+
"strict": false,
46+
"errors": []
47+
},
48+
"errors": {
49+
"lexer": [],
50+
"parser": [
51+
[
52+
"Unexpected beginning of statement.",
53+
{
54+
"@type": "@2"
55+
},
56+
0
57+
]
58+
]
59+
}
60+
}

tests/data/lexer/lexNumber.in

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, 0XFfA, -0xFFa, -0xfFA, -0XFfA, 1e-10, 1e10, .5e10, b'10';
2-
-- invalid number
3-
SELECT 12ex10, b'15';
1+
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, -0xFFa, -0xfFA, 1e-10, 1e10, .5e10, b'10';
2+
-- invalid numbers
3+
SELECT 12ex10, b'15', 0XFfA, -0XFfA;

0 commit comments

Comments
 (0)