Skip to content

Commit

Permalink
Handle backslashes separately for BufferedQuery.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Ungureanu committed Oct 6, 2015
1 parent 4f8868b commit 402890b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Utils/BufferedQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,19 +186,31 @@ public function extract($end = false)
$loopLen = $end ? $len : $len - 16;

for (; $i < $loopLen; ++$i) {
/**
* Handling backslash.
*
* Even if the next character is a special character that should be
* treated differently, because of the preceding backslash, it will
* be ignored.
*/
if ($this->query[$i] === '\\') {
$this->current .= $this->query[$i] . $this->query[++$i];
continue;
}

/*
* Handling special parses statuses.
*/
if ($this->status === static::STATUS_STRING_SINGLE_QUOTES) {
// Single-quoted strings like 'foo'.
if (($this->query[$i - 1] != '\\') && ($this->query[$i] === '\'')) {
if ($this->query[$i] === '\'') {
$this->status = 0;
}
$this->current .= $this->query[$i];
continue;
} elseif ($this->status === static::STATUS_STRING_DOUBLE_QUOTES) {
// Double-quoted strings like "bar".
if (($this->query[$i - 1] != '\\') && ($this->query[$i] === '"')) {
if ($this->query[$i] === '"') {
$this->status = 0;
}
$this->current .= $this->query[$i];
Expand Down
14 changes: 14 additions & 0 deletions tests/Utils/BufferedQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,20 @@ public function testExtractProvider()

return array(

array(
'SELECT """""""";' .
'SELECT """\\\\"""',
8,
array(
'parse_delimiter' => true,
'add_delimiter' => true,
),
array(
'SELECT """""""";',
'SELECT """\\\\"""'
)
),

array(
'DELIMITER A_VERY_LONG_DEL' . "\n" .
'SELECT 1 A_VERY_LONG_DEL' . "\n" .
Expand Down

0 comments on commit 402890b

Please sign in to comment.