Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid hexadecimal prefix 0X #509

Merged
merged 1 commit into from Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/Lexer.php
Expand Up @@ -851,10 +851,7 @@ public function parseNumber()
} elseif (
$this->last + 1 < $this->len
&& $this->str[$this->last] === '0'
&& (
$this->str[$this->last + 1] === 'x'
|| $this->str[$this->last + 1] === 'X'
)
&& $this->str[$this->last + 1] === 'x'
) {
$token .= $this->str[$this->last++];
$state = 2;
Expand Down
1 change: 1 addition & 0 deletions tests/Misc/BugsTest.php
Expand Up @@ -26,6 +26,7 @@ public function bugProvider(): array
['bugs/gh14'],
['bugs/gh16'],
['bugs/gh317'],
['bugs/gh508'],
['bugs/pma11800'],
['bugs/pma11836'],
['bugs/pma11843'],
Expand Down
1 change: 1 addition & 0 deletions tests/data/bugs/gh508.in
@@ -0,0 +1 @@
0X0F
60 changes: 60 additions & 0 deletions tests/data/bugs/gh508.out
@@ -0,0 +1,60 @@
{
"query": "0X0F",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"str": "0X0F",
"len": 4,
"last": 4,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "0X0F",
"value": "0X0F",
"keyword": null,
"type": 0,
"flags": 0,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": null,
"value": null,
"keyword": null,
"type": 9,
"flags": 0,
"position": null
}
],
"count": 2,
"idx": 2
},
"delimiter": ";",
"delimiterLen": 1,
"strict": false,
"errors": []
},
"parser": {
"@type": "PhpMyAdmin\\SqlParser\\Parser",
"list": {
"@type": "@1"
},
"statements": [],
"brackets": 0,
"strict": false,
"errors": []
},
"errors": {
"lexer": [],
"parser": [
[
"Unexpected beginning of statement.",
{
"@type": "@2"
},
0
]
]
}
}
6 changes: 3 additions & 3 deletions tests/data/lexer/lexNumber.in
@@ -1,3 +1,3 @@
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, 0XFfA, -0xFFa, -0xfFA, -0XFfA, 1e-10, 1e10, .5e10, b'10';
-- invalid number
SELECT 12ex10, b'15';
SELECT 12, 34, 5.67, 0x89, -10, --11, +12, .15, 0xFFa, 0xfFA, -0xFFa, -0xfFA, 1e-10, 1e10, .5e10, b'10';
-- invalid numbers
SELECT 12ex10, b'15', 0XFfA, -0XFfA;