@@ -39,16 +39,6 @@ class WP_MySQL_Lexer {
39
39
*/
40
40
const PATTERN_UNQUOTED_IDENTIFIER = '[a-zA-Z0-9_$\x{80}-\x{ffff}]*[a-zA-Z_$\x{80}-\x{ffff}][a-zA-Z0-9_$\x{80}-\x{ffff}]* ' ;
41
41
42
- /**
43
- * Unquoted user-defined variables:
44
- * https://dev.mysql.com/doc/refman/8.4/en/user-variables.html
45
- *
46
- * Rules:
47
- * 1. Starts with a '@'.
48
- * 2. Allowed following characters are ASCII a-z, A-Z, 0-9, ., $, _.
49
- */
50
- const PATTER_UNQUOTED_USER_VARIABLE = '@[a-zA-Z0-9_$.]+ ' ;
51
-
52
42
/**
53
43
* Tokens from the MySQL Workbench "predefined.tokens" list, including token numbers.
54
44
* See:
@@ -2319,19 +2309,30 @@ private function next_token() {
2319
2309
$ this ->consume ();
2320
2310
$ this ->type = self ::CLOSE_CURLY_SYMBOL ;
2321
2311
} elseif ( '@ ' === $ la ) {
2312
+ $ this ->consume (); // Consume the '@'.
2313
+
2322
2314
if ( '@ ' === $ la2 ) {
2323
- $ this ->consume (); // Consume the '@'.
2324
- $ this ->consume (); // Consume the '@'.
2315
+ $ this ->consume (); // Consume the second '@'.
2325
2316
$ this ->type = self ::AT_AT_SIGN_SYMBOL ;
2326
- } elseif ( preg_match ( '/\G ' . self ::PATTER_UNQUOTED_USER_VARIABLE . '/u ' , $ this ->input , $ matches , 0 , $ this ->position ) ) {
2327
- $ this ->text = $ matches [0 ];
2328
- $ this ->position += strlen ( $ this ->text );
2329
- $ this ->c = $ this ->input [ $ this ->position ] ?? null ;
2330
- $ this ->n = $ this ->input [ $ this ->position + 1 ] ?? null ;
2331
- $ this ->type = self ::AT_TEXT_SUFFIX ;
2332
2317
} else {
2333
- $ this ->consume ();
2334
- $ this ->type = self ::AT_SIGN_SYMBOL ;
2318
+ /**
2319
+ * Check whether the '@' marks an unquoted user-defined variable:
2320
+ * https://dev.mysql.com/doc/refman/8.4/en/user-variables.html
2321
+ *
2322
+ * Rules:
2323
+ * 1. Starts with a '@'.
2324
+ * 2. Allowed following characters are ASCII a-z, A-Z, 0-9, _, ., $.
2325
+ */
2326
+ $ length = strspn ( $ this ->input , 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.$ ' , $ this ->position );
2327
+ if ( $ length > 0 ) {
2328
+ $ this ->text = substr ( $ this ->input , $ this ->position , $ length );
2329
+ $ this ->position += $ length ;
2330
+ $ this ->c = $ this ->input [ $ this ->position ] ?? null ;
2331
+ $ this ->n = $ this ->input [ $ this ->position + 1 ] ?? null ;
2332
+ $ this ->type = self ::AT_TEXT_SUFFIX ;
2333
+ } else {
2334
+ $ this ->type = self ::AT_SIGN_SYMBOL ;
2335
+ }
2335
2336
}
2336
2337
} elseif ( '? ' === $ la ) {
2337
2338
$ this ->consume ();
@@ -2574,13 +2575,13 @@ protected function quoted_text( string $quote ) {
2574
2575
}
2575
2576
2576
2577
// Unclosed string - unexpected EOF.
2577
- if ( $ quote !== ( $ this ->input [ $ pos ] ?? null ) ) {
2578
+ if ( ( $ this ->input [ $ pos ] ?? null ) !== $ quote ) {
2578
2579
$ this ->type = self ::INVALID_INPUT ;
2579
2580
return ;
2580
2581
}
2581
2582
2582
2583
// Check if the quote is doubled.
2583
- if ( $ quote === ( $ this ->input [ $ pos + 1 ] ?? null ) ) {
2584
+ if ( ( $ this ->input [ $ pos + 1 ] ?? null ) === $ quote ) {
2584
2585
$ pos += 2 ;
2585
2586
continue ;
2586
2587
}
0 commit comments