Skip to content

Commit 402890b

Browse files
author
Dan Ungureanu
committed
Handle backslashes separately for BufferedQuery.
1 parent 4f8868b commit 402890b

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/Utils/BufferedQuery.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,31 @@ public function extract($end = false)
186186
$loopLen = $end ? $len : $len - 16;
187187

188188
for (; $i < $loopLen; ++$i) {
189+
/**
190+
* Handling backslash.
191+
*
192+
* Even if the next character is a special character that should be
193+
* treated differently, because of the preceding backslash, it will
194+
* be ignored.
195+
*/
196+
if ($this->query[$i] === '\\') {
197+
$this->current .= $this->query[$i] . $this->query[++$i];
198+
continue;
199+
}
200+
189201
/*
190202
* Handling special parses statuses.
191203
*/
192204
if ($this->status === static::STATUS_STRING_SINGLE_QUOTES) {
193205
// Single-quoted strings like 'foo'.
194-
if (($this->query[$i - 1] != '\\') && ($this->query[$i] === '\'')) {
206+
if ($this->query[$i] === '\'') {
195207
$this->status = 0;
196208
}
197209
$this->current .= $this->query[$i];
198210
continue;
199211
} elseif ($this->status === static::STATUS_STRING_DOUBLE_QUOTES) {
200212
// Double-quoted strings like "bar".
201-
if (($this->query[$i - 1] != '\\') && ($this->query[$i] === '"')) {
213+
if ($this->query[$i] === '"') {
202214
$this->status = 0;
203215
}
204216
$this->current .= $this->query[$i];

tests/Utils/BufferedQueryTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,20 @@ public function testExtractProvider()
100100

101101
return array(
102102

103+
array(
104+
'SELECT """""""";' .
105+
'SELECT """\\\\"""',
106+
8,
107+
array(
108+
'parse_delimiter' => true,
109+
'add_delimiter' => true,
110+
),
111+
array(
112+
'SELECT """""""";',
113+
'SELECT """\\\\"""'
114+
)
115+
),
116+
103117
array(
104118
'DELIMITER A_VERY_LONG_DEL' . "\n" .
105119
'SELECT 1 A_VERY_LONG_DEL' . "\n" .

0 commit comments

Comments
 (0)