Skip to content

Commit 79f24f9

Browse files
committed
Interpret escape sequences only in strings that support it
1 parent 8e78cf7 commit 79f24f9

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/Import.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,22 @@ public function parse_statements( $sql_file_path ) {
8989
for ( $i = 0; $i < $strlen; $i++ ) {
9090
$ch = $line[ $i ];
9191

92-
// Count preceding backslashes.
93-
$slashes = 0;
94-
while ( $slashes < $i && '\\' === $line[ $i - $slashes - 1 ] ) {
95-
++$slashes;
96-
}
92+
// Handle escape sequences in single and double quoted strings.
93+
// TODO: Support NO_BACKSLASH_ESCAPES SQL mode.
94+
if ( "'" === $ch || '"' === $ch ) {
95+
// Count preceding backslashes.
96+
$slashes = 0;
97+
while ( $slashes < $i && '\\' === $line[ $i - $slashes - 1 ] ) {
98+
++$slashes;
99+
}
97100

98-
// Handle escaped characters.
99-
// A characters is escaped only when the number of preceding backslashes
100-
// is odd - "\" is an escape sequence, "\\" is an escaped backslash.
101-
if ( 1 === $slashes % 2 ) {
102-
$buffer .= $ch;
103-
continue;
101+
// Handle escaped characters.
102+
// A characters is escaped only when the number of preceding backslashes
103+
// is odd - "\" is an escape sequence, "\\" is an escaped backslash.
104+
if ( 1 === $slashes % 2 ) {
105+
$buffer .= $ch;
106+
continue;
107+
}
104108
}
105109

106110
// Handle comments.

0 commit comments

Comments
 (0)