Skip to content

Commit 15f8e0a

Browse files
committed
Fix character escaping to support escaped backslashes
1 parent 92c3558 commit 15f8e0a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Import.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ public function parse_statements( $sql_file_path ) {
102102
for ( $i = 0; $i < $strlen; $i++ ) {
103103
$ch = $line[ $i ];
104104

105-
// Handle escaped characters
106-
if ( $i > 0 && '\\' === $line[ $i - 1 ] ) {
105+
// Count preceding backslashes.
106+
for ( $slashes = 0; '\\' === ( $line[ $slashes - $i - 1 ] ?? null ); $slashes += 1 );
107+
108+
// Handle escaped characters.
109+
// A characters is escaped only when the number of preceding backslashes
110+
// is odd - "\" is an escape sequence, "\\" is an escaped backslash.
111+
if ( 1 === $slashes % 2 ) {
107112
$buffer .= $ch;
108113
continue;
109114
}

0 commit comments

Comments
 (0)