Use strings to represent wildcard characters

A string is made of characters, an array might contain anything.
parent a9e5e5a9
...@@ -43,7 +43,6 @@ use Doctrine\DBAL\TransactionIsolationLevel; ...@@ -43,7 +43,6 @@ use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types; use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use function addcslashes; use function addcslashes;
use function implode;
use function preg_quote; use function preg_quote;
use function preg_replace; use function preg_replace;
use function sprintf; use function sprintf;
...@@ -3596,17 +3595,14 @@ abstract class AbstractPlatform ...@@ -3596,17 +3595,14 @@ abstract class AbstractPlatform
final public function escapeStringForLike(string $inputString, string $escapeChar) : string final public function escapeStringForLike(string $inputString, string $escapeChar) : string
{ {
return preg_replace( return preg_replace(
'~([' . preg_quote(implode('', $this->getLikeWildcardCharacters()) . $escapeChar, '~') . '])~u', '~([' . preg_quote($this->getLikeWildcardCharacters() . $escapeChar, '~') . '])~u',
addcslashes($escapeChar, '\\') . '$1', addcslashes($escapeChar, '\\') . '$1',
$inputString $inputString
); );
} }
/** protected function getLikeWildcardCharacters() : string
* @return string[]
*/
protected function getLikeWildcardCharacters() : array
{ {
return ['%', '_']; return '%_';
} }
} }
...@@ -117,11 +117,8 @@ class SQLServer2008Platform extends SQLServer2005Platform ...@@ -117,11 +117,8 @@ class SQLServer2008Platform extends SQLServer2005Platform
return Keywords\SQLServer2008Keywords::class; return Keywords\SQLServer2008Keywords::class;
} }
/** protected function getLikeWildcardCharacters() : string
* {@inheritDoc}
*/
protected function getLikeWildcardCharacters() : array
{ {
return array_merge(parent::getLikeWildcardCharacters(), ['[', ']', '^']); return parent::getLikeWildcardCharacters() . '[]^';
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment