summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2016-04-19 15:17:25 +0200
committerMichal Čihař <michal@cihar.com>2016-04-19 15:17:25 +0200
commit84c8ba677d4f27b2a02c9e1bae5e9d0356575338 (patch)
tree49e55cfd15796da4eb197b421ae8fbedeb1e0b54
parentd8547b8f711a084a4d1f1ee3c79b0c7c15198fad (diff)
downloadsql-parser-84c8ba677d4f27b2a02c9e1bae5e9d0356575338.zip
sql-parser-84c8ba677d4f27b2a02c9e1bae5e9d0356575338.tar.gz
sql-parser-84c8ba677d4f27b2a02c9e1bae5e9d0356575338.tar.bz2
Fix parsing of query with \v3.4.3
The previous fix was wrong, it didn't properly handle double escaping. Fixes https://github.com/phpmyadmin/phpmyadmin/issues/12197 Signed-off-by: Michal Čihař <michal@cihar.com>
-rw-r--r--src/Utils/BufferedQuery.php6
-rw-r--r--tests/Utils/BufferedQueryTest.php22
2 files changed, 25 insertions, 3 deletions
diff --git a/src/Utils/BufferedQuery.php b/src/Utils/BufferedQuery.php
index 500862a..8aad59f 100644
--- a/src/Utils/BufferedQuery.php
+++ b/src/Utils/BufferedQuery.php
@@ -199,7 +199,7 @@ class BufferedQuery
* treated differently, because of the preceding backslash, it will
* be ignored.
*/
- if (($this->status & static::STATUS_COMMENT == 0) && ($this->query[$i] === '\\')) {
+ if ((($this->status & static::STATUS_COMMENT) == 0) && ($this->query[$i] === '\\')) {
$this->current .= $this->query[$i] . $this->query[++$i];
continue;
}
@@ -209,14 +209,14 @@ class BufferedQuery
*/
if ($this->status === static::STATUS_STRING_SINGLE_QUOTES) {
// Single-quoted strings like 'foo'.
- if ($this->query[$i] === '\'' && $this->query[$i - 1] !== '\\') {
+ 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] === '"' && $this->query[$i - 1] !== '\\') {
+ if ($this->query[$i] === '"') {
$this->status = 0;
}
$this->current .= $this->query[$i];
diff --git a/tests/Utils/BufferedQueryTest.php b/tests/Utils/BufferedQueryTest.php
index ae406a4..41e14ff 100644
--- a/tests/Utils/BufferedQueryTest.php
+++ b/tests/Utils/BufferedQueryTest.php
@@ -114,6 +114,28 @@ class BufferedQueryTest extends TestCase
),
array(
+ "CREATE TABLE `test` (\n" .
+ " `txt` varchar(10)\n" .
+ ");\n" .
+ "INSERT INTO `test` (`txt`) VALUES('abc');\n" .
+ "INSERT INTO `test` (`txt`) VALUES('\\\\');\n" .
+ "INSERT INTO `test` (`txt`) VALUES('xyz');\n",
+ 8,
+ array(
+ 'parse_delimiter' => true,
+ 'add_delimiter' => true,
+ ),
+ array(
+ "CREATE TABLE `test` (\n" .
+ " `txt` varchar(10)\n" .
+ ");",
+ "INSERT INTO `test` (`txt`) VALUES('abc');",
+ "INSERT INTO `test` (`txt`) VALUES('\\\\');",
+ "INSERT INTO `test` (`txt`) VALUES('xyz');",
+ )
+ ),
+
+ array(
'SELECT """""""";' .
'SELECT """\\\\"""',
8,