Skip to content

Commit 8e78cf7

Browse files
committed
Correctly parse backtick-quoted strings
1 parent a84c954 commit 8e78cf7

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

‎features/bootstrap/SQLiteFeatureContext.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function aSqlDumpFileNamedWithContent( $filename, PyStringNode $content )
2525
*/
2626
public function theSqliteDatabaseShouldContainATableNamed( $table_name ) {
2727
$this->connectToDatabase();
28-
$result = $this->db->query( "SELECT name FROM sqlite_master WHERE type='table' AND name='$table_name'" );
28+
$result = $this->db->query( "SELECT name FROM sqlite_master WHERE type='table' AND name='" . $this->db->escapeString( $table_name ) . "'" );
2929
$row = $result->fetchArray();
3030
if ( ! $row ) {
3131
throw new Exception( "Table '$table_name' not found in the database." );

‎features/sqlite-import.feature‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,17 @@ Feature: WP-CLI SQLite Import Command
137137
"""
138138
a double-quoted string with ' some " " tricky ` chars
139139
"""
140+
141+
@require-sqlite
142+
Scenario: Import a file backtick-quoted identifiers
143+
Given a SQL dump file named "test_import.sql" with content:
144+
"""
145+
CREATE TABLE `a'strange``identifier\\name` (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
146+
"""
147+
When I run `wp sqlite --enable-ast-driver import test_import.sql`
148+
Then STDOUT should contain:
149+
"""
150+
Success: Imported from 'test_import.sql'.
151+
"""
152+
153+
And the SQLite database should contain a table named "a'strange`identifier\name"

‎src/Import.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function parse_statements( $sql_file_path ) {
127127
}
128128

129129
// Handle quotes
130-
if ( null === $starting_quote && ( "'" === $ch || '"' === $ch ) ) {
130+
if ( null === $starting_quote && ( "'" === $ch || '"' === $ch || '`' === $ch ) ) {
131131
$starting_quote = $ch;
132132
} elseif ( null !== $starting_quote && $ch === $starting_quote ) {
133133
$starting_quote = null;

0 commit comments

Comments
 (0)