File tree Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Expand file tree Collapse file tree 4 files changed +41
-4
lines changed Original file line number Diff line number Diff line change @@ -332,18 +332,28 @@ public static function isComment($str, $end = false)
332
332
if ($ len === 0 ) {
333
333
return null ;
334
334
}
335
+
336
+ // If comment is Bash style (#):
335
337
if ($ str [0 ] === '# ' ) {
336
338
return Token::FLAG_COMMENT_BASH ;
337
- } elseif (($ len > 1 ) && ($ str [0 ] === '/ ' ) && ($ str [1 ] === '* ' )) {
339
+ }
340
+ // If comment is opening C style (/*), warning, it could be a MySQL command (/*!)
341
+ if (($ len > 1 ) && ($ str [0 ] === '/ ' ) && ($ str [1 ] === '* ' )) {
338
342
return ($ len > 2 ) && ($ str [2 ] === '! ' ) ?
339
343
Token::FLAG_COMMENT_MYSQL_CMD : Token::FLAG_COMMENT_C ;
340
- } elseif (($ len > 1 ) && ($ str [0 ] === '* ' ) && ($ str [1 ] === '/ ' )) {
344
+ }
345
+ // If comment is closing C style (*/), warning, it could conflicts with wildcard and a real opening C style.
346
+ // It would looks like the following valid SQL statement: "SELECT */* comment */ FROM...".
347
+ if (($ len > 1 ) && ($ str [0 ] === '* ' ) && ($ str [1 ] === '/ ' )) {
341
348
return Token::FLAG_COMMENT_C ;
342
- } elseif (($ len > 2 ) && ($ str [0 ] === '- ' )
349
+ }
350
+ // If comment is SQL style (--\s?):
351
+ if (($ len > 2 ) && ($ str [0 ] === '- ' )
343
352
&& ($ str [1 ] === '- ' ) && static ::isWhitespace ($ str [2 ])
344
353
) {
345
354
return Token::FLAG_COMMENT_SQL ;
346
- } elseif (($ len === 2 ) && $ end && ($ str [0 ] === '- ' ) && ($ str [1 ] === '- ' )) {
355
+ }
356
+ if (($ len === 2 ) && $ end && ($ str [0 ] === '- ' ) && ($ str [1 ] === '- ' )) {
347
357
return Token::FLAG_COMMENT_SQL ;
348
358
}
349
359
Original file line number Diff line number Diff line change @@ -553,6 +553,19 @@ public function parseComment()
553
553
if (++$ this ->last < $ this ->len ) {
554
554
$ token .= $ this ->str [$ this ->last ];
555
555
if (Context::isComment ($ token )) {
556
+ // There might be a conflict with "*" operator here, when string is "*/*".
557
+ // This can occurs in the following statements:
558
+ // - "SELECT */* comment */ FROM ..."
559
+ // - "SELECT 2*/* comment */3 AS `six`;"
560
+ $ next = $ this ->last +1 ;
561
+ if (($ next < $ this ->len ) && $ this ->str [$ next ] === '* ' ) {
562
+ // Conflict in "*/*": first "*" was not for ending a comment.
563
+ // Stop here and let other parsing method define the true behavior of that first star.
564
+ $ this ->last = $ iBak ;
565
+
566
+ return null ;
567
+ }
568
+
556
569
$ flags = Token::FLAG_COMMENT_C ;
557
570
558
571
// This comment already ended. It may be a part of a
Original file line number Diff line number Diff line change
1
+ SELECT */* comment */
2
+ SELECT /* comment */*
3
+ SELECT 2*/* comment */3
4
+ SELECT 2/* comment */*3
Original file line number Diff line number Diff line change
1
+ a:4:{s:5:"query";s:91:"SELECT */* comment */
2
+ SELECT /* comment */*
3
+ SELECT 2*/* comment */3
4
+ SELECT 2/* comment */*3";s:5:"lexer";O:26:"PhpMyAdmin\SqlParser\Lexer":8:{s:3:"str";s:91:"SELECT */* comment */
5
+ SELECT /* comment */*
6
+ SELECT 2*/* comment */3
7
+ SELECT 2/* comment */*3";s:3:"len";i:91;s:4:"last";i:91;s:4:"list";O:31:"PhpMyAdmin\SqlParser\TokensList":3:{s:6:"tokens";a:24:{i:0;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:6:"SELECT";s:5:"value";s:6:"SELECT";s:7:"keyword";s:6:"SELECT";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:0;}i:1;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:6;}i:2;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"*";s:5:"value";s:1:"*";s:7:"keyword";N;s:4:"type";i:2;s:5:"flags";i:1;s:8:"position";i:7;}i:3;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:13:"/* comment */";s:5:"value";s:13:"/* comment */";s:7:"keyword";N;s:4:"type";i:4;s:5:"flags";i:2;s:8:"position";i:8;}i:4;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"
8
+ ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:21;}i:5;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:6:"SELECT";s:5:"value";s:6:"SELECT";s:7:"keyword";s:6:"SELECT";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:22;}i:6;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:28;}i:7;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:13:"/* comment */";s:5:"value";s:13:"/* comment */";s:7:"keyword";N;s:4:"type";i:4;s:5:"flags";i:2;s:8:"position";i:29;}i:8;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"*";s:5:"value";s:1:"*";s:7:"keyword";N;s:4:"type";i:2;s:5:"flags";i:1;s:8:"position";i:42;}i:9;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"
9
+ ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:43;}i:10;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:6:"SELECT";s:5:"value";s:6:"SELECT";s:7:"keyword";s:6:"SELECT";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:44;}i:11;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:50;}i:12;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"2";s:5:"value";i:2;s:7:"keyword";N;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:51;}i:13;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"*";s:5:"value";s:1:"*";s:7:"keyword";N;s:4:"type";i:2;s:5:"flags";i:1;s:8:"position";i:52;}i:14;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:13:"/* comment */";s:5:"value";s:13:"/* comment */";s:7:"keyword";N;s:4:"type";i:4;s:5:"flags";i:2;s:8:"position";i:53;}i:15;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"3";s:5:"value";i:3;s:7:"keyword";N;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:66;}i:16;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"
10
+ ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:67;}i:17;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:6:"SELECT";s:5:"value";s:6:"SELECT";s:7:"keyword";s:6:"SELECT";s:4:"type";i:1;s:5:"flags";i:3;s:8:"position";i:68;}i:18;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:" ";s:5:"value";s:1:" ";s:7:"keyword";N;s:4:"type";i:3;s:5:"flags";i:0;s:8:"position";i:74;}i:19;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"2";s:5:"value";i:2;s:7:"keyword";N;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:75;}i:20;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:13:"/* comment */";s:5:"value";s:13:"/* comment */";s:7:"keyword";N;s:4:"type";i:4;s:5:"flags";i:2;s:8:"position";i:76;}i:21;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"*";s:5:"value";s:1:"*";s:7:"keyword";N;s:4:"type";i:2;s:5:"flags";i:1;s:8:"position";i:89;}i:22;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";s:1:"3";s:5:"value";i:3;s:7:"keyword";N;s:4:"type";i:6;s:5:"flags";i:0;s:8:"position";i:90;}i:23;O:26:"PhpMyAdmin\SqlParser\Token":6:{s:5:"token";N;s:5:"value";N;s:7:"keyword";N;s:4:"type";i:9;s:5:"flags";i:0;s:8:"position";N;}}s:5:"count";i:24;s:3:"idx";i:0;}s:9:"delimiter";s:1:";";s:12:"delimiterLen";i:1;s:6:"strict";b:0;s:6:"errors";a:0:{}}s:6:"parser";N;s:6:"errors";a:2:{s:5:"lexer";a:0:{}s:6:"parser";a:0:{}}}
You can’t perform that action at this time.
0 commit comments