From 186035e6c2b0f4b2d5c3fa4f98e9a25f2d9b27a3 Mon Sep 17 00:00:00 2001 From: TPHRyan Date: Wed, 27 Mar 2019 13:11:35 +1000 Subject: [PATCH] Fix quotes in comments breaking parameters An odd number of quotes in comments would cause getUnquotedStatementFragments to start returning the inside of strings, rather than the outside. Ignore comment lines to solve this problem. --- lib/Doctrine/DBAL/SQLParserUtils.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/SQLParserUtils.php b/lib/Doctrine/DBAL/SQLParserUtils.php index 0ff0456a00e..c25a4af2ddd 100644 --- a/lib/Doctrine/DBAL/SQLParserUtils.php +++ b/lib/Doctrine/DBAL/SQLParserUtils.php @@ -4,6 +4,7 @@ use const PREG_OFFSET_CAPTURE; use function array_fill; +use function array_filter; use function array_key_exists; use function array_merge; use function array_slice; @@ -250,11 +251,12 @@ private static function getUnquotedStatementFragments($statement) self::ESCAPED_DOUBLE_QUOTED_TEXT . '|' . self::ESCAPED_BACKTICK_QUOTED_TEXT . '|' . self::ESCAPED_BRACKET_QUOTED_TEXT; - $expression = sprintf('/((.+(?i:ARRAY)\\[.+\\])|([^\'"`\\[]+))(?:%s)?/s', $literal); - + $expression = sprintf('/(?:[\s]*--.*?\n)|((.+(?i:ARRAY)\\[.+\\])|([^-\'"`\\[]+))(?:%s)?/s', $literal); preg_match_all($expression, $statement, $fragments, PREG_OFFSET_CAPTURE); - return $fragments[1]; + return array_filter($fragments[1], static function ($match) { + return $match !== ''; + }); } /**