Skip to content

Commit c13b4d3

Browse files
committed
Extract the identifier characters into a lexer constant
Both lexers repeated the ASCII characters allowed in an unquoted identifier in read_identifier() and in the "@" variable name scan.
1 parent 7e1073d commit c13b4d3

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎packages/mysql-on-sqlite/src/mysql/class-wp-mysql-lexer.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class WP_MySQL_Lexer {
4545
const WHITESPACE_MASK = " \t\n\r\f\v";
4646
const DIGIT_MASK = '0123456789';
4747
const HEX_DIGIT_MASK = '0123456789abcdefABCDEF';
48+
const IDENTIFIER_MASK = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$';
4849

4950
/**
5051
* Tokens from the MySQL Workbench "predefined.tokens" list.
@@ -2612,7 +2613,7 @@ private function read_next_token(): ?int {
26122613
* 1. Starts with a '@'.
26132614
* 2. Allowed following characters are ASCII a-z, A-Z, 0-9, _, ., $.
26142615
*/
2615-
$length = strspn( $this->sql, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.$', $this->bytes_already_read );
2616+
$length = strspn( $this->sql, self::IDENTIFIER_MASK . '.', $this->bytes_already_read );
26162617
if ( $length > 0 ) {
26172618
$this->bytes_already_read += $length;
26182619
$type = self::AT_TEXT_SUFFIX;
@@ -2689,7 +2690,7 @@ private function read_identifier(): ?int {
26892690
// First, let's try to parse an ASCII sequence.
26902691
$this->bytes_already_read += strspn(
26912692
$this->sql,
2692-
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$',
2693+
self::IDENTIFIER_MASK,
26932694
$this->bytes_already_read
26942695
);
26952696

‎packages/mysql-parser/src/class-wp-mysql-lexer.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class WP_MySQL_Lexer {
125125
private const WHITESPACE_MASK = " \t\n\r\f\v";
126126
private const DIGIT_MASK = '0123456789';
127127
private const HEX_DIGIT_MASK = '0123456789abcdefABCDEF';
128+
private const IDENTIFIER_MASK = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$';
128129

129130
/**
130131
* Internal scanner sentinels.
@@ -672,7 +673,7 @@ private function produce_at_variable( array &$out, int $at_start ): void {
672673

673674
$name_length = strspn(
674675
$this->sql,
675-
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.$',
676+
self::IDENTIFIER_MASK . '.',
676677
$position
677678
);
678679
if ( $name_length > 0 ) {
@@ -991,7 +992,7 @@ private function read_identifier(): ?int {
991992
// First, let's try to parse an ASCII sequence.
992993
$this->bytes_already_read += strspn(
993994
$this->sql,
994-
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$',
995+
self::IDENTIFIER_MASK,
995996
$this->bytes_already_read
996997
);
997998

0 commit comments

Comments
 (0)