Skip to content

Commit 6c22b98

Browse files
committed
Fix whitespace being trimmed in multi-line strings
1 parent da3e71a commit 6c22b98

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

‎features/bootstrap/SQLiteFeatureContext.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function theSqliteDatabaseShouldContainATableNamed( $table_name ) {
3434

3535
/**
3636
* @Then /^the "([^"]*)" should contain a row with name "([^"]*)"$/
37+
* @Then /^the "([^"]*)" should contain a row with name:$/
3738
*/
3839
public function theTableShouldContainARowWithName( $table_name, $name ) {
3940
$this->connectToDatabase();

‎features/sqlite-import.feature‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,23 @@ Feature: WP-CLI SQLite Import Command
6767
And the "test_table" should contain a row with name "Test that escaping a character \a works"
6868
And the "test_table" should contain a row with name "Test that escaping a backslash followed by a character \\a works"
6969
And the "test_table" should contain a row with name "Test that escaping a backslash and a character \\\a works"
70+
71+
@require-sqlite
72+
Scenario: Import a file with newlines in strings
73+
Given a SQL dump file named "test_import.sql" with content:
74+
"""
75+
CREATE TABLE test_table (id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT);
76+
INSERT INTO test_table (name) VALUES ('Test that a string containing
77+
a newline character and some whitespace works');
78+
"""
79+
When I run `wp sqlite --enable-ast-driver import test_import.sql`
80+
Then STDOUT should contain:
81+
"""
82+
Success: Imported from 'test_import.sql'.
83+
"""
84+
And the SQLite database should contain a table named "test_table"
85+
And the "test_table" should contain a row with name:
86+
"""
87+
Test that a string containing
88+
a newline character and some whitespace works
89+
"""

‎src/Import.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ public function parse_statements( $sql_file_path ) {
8686
$line = mb_convert_encoding( $line, 'UTF-8', $detected_encoding );
8787
}
8888

89-
$line = trim( $line );
90-
9189
// Skip empty lines and comments
9290
if ( empty( $line ) || strpos( $line, '--' ) === 0 || strpos( $line, '#' ) === 0 ) {
9391
continue;

0 commit comments

Comments
 (0)