Skip to content

Commit

Permalink
Fix quotes in comments breaking parameters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TPHRyan committed Mar 27, 2019
1 parent 546cd67 commit 186035e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/Doctrine/DBAL/SQLParserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 !== '';
});
}

/**
Expand Down

0 comments on commit 186035e

Please sign in to comment.