Skip to content

Commit 35f656f

Browse files
committed
Drop an unused argument from a read_quoted_text() call
read_quoted_text() reads the quote character from the input and takes no arguments, so the "'" passed for N'...' literals was silently ignored. Add tests for national string literals, which had no direct lexer coverage.
1 parent 6a6f5b5 commit 35f656f

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ private function read_next_token(): ?int {
10111011
$type = $this->read_number();
10121012
} elseif ( ( 'n' === $byte || 'N' === $byte ) && "'" === $next_byte ) {
10131013
$this->bytes_already_read += 1;
1014-
$type = $this->read_quoted_text( "'" );
1014+
$type = $this->read_quoted_text();
10151015
if ( self::TEXT_STRING === $type ) {
10161016
$type = self::NCHAR_STRING;
10171017
}

‎packages/mysql-parser/tests/WP_MySQL_Lexer_Tests.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,22 @@ public function data_ansi_quotes_tokenization(): array {
764764
);
765765
}
766766

767+
/**
768+
* @dataProvider data_national_strings
769+
*/
770+
public function test_national_strings( string $sql, array $expected ): void {
771+
$this->assertSame( array_merge( $expected, array( 'END_OF_INPUT', 'YYEOF' ) ), self::token_names( $sql ) );
772+
}
773+
774+
public function data_national_strings(): array {
775+
return array(
776+
'uppercase prefix' => array( "N'abc'", array( 'NCHAR_STRING' ) ),
777+
'lowercase prefix' => array( "n'abc'", array( 'NCHAR_STRING' ) ),
778+
'escaped quote' => array( "N'a''b'", array( 'NCHAR_STRING' ) ),
779+
'double quote is not a literal' => array( 'N"abc"', array( 'IDENT', 'TEXT_STRING' ) ),
780+
);
781+
}
782+
767783
public function test_composite_ansi_mode_expands_to_lexer_component_modes(): void {
768784
// ANSI_QUOTES: a double-quoted sequence is a quoted identifier.
769785
$lexer = new WP_MySQL_Lexer( '"foo"', 80400, array( 'ANSI' ) );

0 commit comments

Comments
 (0)