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;
use Doctrine\DBAL\Types;
use Doctrine\DBAL\Types\Type;
use function addcslashes;
use function implode;
use function preg_quote;
use function preg_replace;
use function sprintf;
......@@ -3596,17 +3595,14 @@ abstract class AbstractPlatform
final public function escapeStringForLike(string $inputString, string $escapeChar) : string
{
return preg_replace(
'~([' . preg_quote(implode('', $this->getLikeWildcardCharacters()) . $escapeChar, '~') . '])~u',
'~([' . preg_quote($this->getLikeWildcardCharacters() . $escapeChar, '~') . '])~u',
addcslashes($escapeChar, '\\') . '$1',
$inputString
);
}
/**
* @return string[]
*/
protected function getLikeWildcardCharacters() : array
protected function getLikeWildcardCharacters() : string
{
return ['%', '_'];
return '%_';
}
}
......@@ -117,11 +117,8 @@ class SQLServer2008Platform extends SQLServer2005Platform
return Keywords\SQLServer2008Keywords::class;
}
/**
* {@inheritDoc}
*/
protected function getLikeWildcardCharacters() : array
protected function getLikeWildcardCharacters() : string
{
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