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 cstyle comment with two asterisks #597

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ public function parseComment()
// - "SELECT */* comment */ FROM ..."
// - "SELECT 2*/* comment */3 AS `six`;"
$next = $this->last + 1;
if (($next < $this->len) && $this->str[$next] === '*') {
if (($next < $this->len) && $this->str[$next] === '*' && $token === '*/') {
// Conflict in "*/*": first "*" was not for ending a comment.
// Stop here and let other parsing method define the true behavior of that first star.
$this->last = $iBak;
Expand Down
1 change: 1 addition & 0 deletions tests/Lexer/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public static function lexProvider(): array
['lexer/lexOperator'],
['lexer/lexOperatorStarIsArithmetic'],
['lexer/lexOperatorStarIsWildcard'],
['lexer/lexEmptyCStyleComment'],
['lexer/lexString'],
['lexer/lexStringErr1'],
['lexer/lexSymbol'],
Expand Down
5 changes: 5 additions & 0 deletions tests/data/lexer/lexEmptyCStyleComment.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT /**/ 1
SELECT /*+*/ 1
SELECT /***/ 1
SELECT /** */ 1
SELECT /* **/ 1
304 changes: 304 additions & 0 deletions tests/data/lexer/lexEmptyCStyleComment.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,304 @@
{
"query": "SELECT /**/ 1\nSELECT /*+*/ 1\nSELECT /***/ 1\nSELECT /** */ 1\nSELECT /* **/ 1\n",
"lexer": {
"@type": "PhpMyAdmin\\SqlParser\\Lexer",
"str": "SELECT /**/ 1\nSELECT /*+*/ 1\nSELECT /***/ 1\nSELECT /** */ 1\nSELECT /* **/ 1\n",
"len": 76,
"last": 76,
"list": {
"@type": "PhpMyAdmin\\SqlParser\\TokensList",
"tokens": [
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 0
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 6
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/**/",
"value": "/**/",
"keyword": null,
"type": 4,
"flags": 2,
"position": 7
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 11
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 12
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 13
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 14
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 20
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/*+*/",
"value": "/*+*/",
"keyword": null,
"type": 4,
"flags": 2,
"position": 21
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 26
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 27
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 28
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 29
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 35
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/***/",
"value": "/***/",
"keyword": null,
"type": 4,
"flags": 2,
"position": 36
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 41
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 42
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 43
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 44
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 50
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/** */",
"value": "/** */",
"keyword": null,
"type": 4,
"flags": 2,
"position": 51
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 57
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 58
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 59
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "SELECT",
"value": "SELECT",
"keyword": "SELECT",
"type": 1,
"flags": 3,
"position": 60
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 66
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "/* **/",
"value": "/* **/",
"keyword": null,
"type": 4,
"flags": 2,
"position": 67
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": " ",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 73
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "1",
"value": 1,
"keyword": null,
"type": 6,
"flags": 0,
"position": 74
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": "\n",
"value": " ",
"keyword": null,
"type": 3,
"flags": 0,
"position": 75
},
{
"@type": "PhpMyAdmin\\SqlParser\\Token",
"token": null,
"value": null,
"keyword": null,
"type": 9,
"flags": 0,
"position": null
}
],
"count": 31,
"idx": 0
},
"delimiter": ";",
"delimiterLen": 1,
"strict": false,
"errors": []
},
"parser": null,
"errors": {
"lexer": [],
"parser": []
}
}
4 changes: 2 additions & 2 deletions tests/data/lexer/lexOperatorStarIsWildcard.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SELECT a.*, b.* FROM
SELECT a.*, /* with a comment */ b.* FROM
SELECT a.*,/* with a comment */b.* FROM
SELECT a.* /* comment */ FROM
-- SELECT a.*/* comment */ FROM (This one is not working yet because of https://github.com/phpmyadmin/sql-parser/issues/285. Please uncomment when this issue is fixed.)
SELECT a.*/* comment */ FROM
SELECT DISTINCT * FROM
SELECT DISTINCT *FROM
SELECT DISTINCT a.* FROM
Expand All @@ -15,7 +15,7 @@ SELECT DISTINCT a.*, b.* FROM
SELECT DISTINCT a.*, /* with a comment */ b.* FROM
SELECT DISTINCT a.*,/* with a comment */b.* FROM
SELECT DISTINCT a.* /* comment */ FROM
-- SELECT DISTINCT a.*/* comment */ FROM (This one is not working yet because of https://github.com/phpmyadmin/sql-parser/issues/285. Please uncomment when this issue is fixed.)
SELECT DISTINCT a.*/* comment */ FROM
SELECT `*` FROM table_name
SELECT `*`.* FROM table_name AS `*`
SELECT COUNT(*) FROM table_name
Expand Down
Loading
Loading