summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2016-03-02 13:41:25 +0100
committerMichal Čihař <michal@cihar.com>2016-03-02 13:43:42 +0100
commitd2e37de1dbec251556f35712bddcd61d24baaee6 (patch)
treedb4b752477439b917532c445969503d4efebbe2a
parentcf246a37afde716c8d7adeba7bffcdad86ac7ccf (diff)
downloadsql-parser-d2e37de1dbec251556f35712bddcd61d24baaee6.zip
sql-parser-d2e37de1dbec251556f35712bddcd61d24baaee6.tar.gz
sql-parser-d2e37de1dbec251556f35712bddcd61d24baaee6.tar.bz2
Fix splitting query when escaped quotes are involved
Fixes https://github.com/phpmyadmin/phpmyadmin/issues/12054 Signed-off-by: Michal Čihař <michal@cihar.com>
-rw-r--r--src/Utils/BufferedQuery.php4
-rw-r--r--tests/Utils/BufferedQueryTest.php13
2 files changed, 15 insertions, 2 deletions
diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php
index 1aaa9d7..500862a 100644
--- a/src/Utils/BufferedQuery.php
+++ b/src/Utils/BufferedQuery.php
@@ -209,14 +209,14 @@ class BufferedQuery
*/
if ($this->status === static::STATUS_STRING_SINGLE_QUOTES) {
// Single-quoted strings like 'foo'.
- if ($this->query[$i] === '\'') {
+ if ($this->query[$i] === '\'' && $this->query[$i - 1] !== '\\') {
$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] === '"') {
+ if ($this->query[$i] === '"' && $this->query[$i - 1] !== '\\') {
$this->status = 0;
}
$this->current .= $this->query[$i];
diff --git a/tests/Utils/BufferedQueryTest.php b/tests/Utils/BufferedQueryTest.php
index a6bf3ed..ae406a4 100644
--- a/tests/Utils/BufferedQueryTest.php
+++ b/tests/Utils/BufferedQueryTest.php
@@ -101,6 +101,19 @@ class BufferedQueryTest extends TestCase
return array(
array(
+ "SELECT '\'';\nSELECT '\'';",
+ 8,
+ array(
+ 'parse_delimiter' => true,
+ 'add_delimiter' => true,
+ ),
+ array(
+ "SELECT '\'';",
+ "SELECT '\'';",
+ )
+ ),
+
+ array(
'SELECT """""""";' .
'SELECT """\\\\"""',
8,