Skip to content

Commit

Permalink
Merge pull request #509 from MauricioFauth/invalid-hex
Browse files Browse the repository at this point in the history
Fix invalid hexadecimal prefix 0X
  • Loading branch information
MauricioFauth authored Sep 15, 2023
2 parents c5a8c54 + 796b135 commit 78f7b23
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 95 deletions.
5 changes: 1 addition & 4 deletions src/Lexer.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0X0F
60 changes: 60 additions & 0 deletions tests/data/bugs/gh508.out
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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;
Loading

0 comments on commit 78f7b23

Please sign in to comment.