@@ -3582,21 +3582,29 @@ public function getStringLiteralQuoteCharacter()
3582
3582
/**
3583
3583
* Escapes metacharacters in a string intended to be used with a LIKE
3584
3584
* operator.
3585
+ *
3586
+ * @param string $inputString a literal, unquoted string
3587
+ * @param string $escapeChar should be exactly one character long and
3588
+ * should be reused by the caller in the LIKE
3589
+ * expression.
3585
3590
*/
3586
- final public function escapeStringForLike (string $ inputString ): string
3591
+ final public function escapeStringForLike (string $ inputString, string $ escapeChar ): string
3587
3592
{
3588
- $ escapeChar = $ this ->getLikeEscapeChar ();
3593
+ /* Some RDBMS' can deal with multibyte characters, but let us assume
3594
+ * that kind of will not actually be needed */
3595
+ $ escapeCharLength = \strlen ($ escapeChar );
3596
+ if ($ escapeCharLength !== 1 ) {
3597
+ throw new \InvalidArgumentException (sprintf (
3598
+ 'The escape character should be exactly that, got "%s" ' ,
3599
+ $ escapeCharLength
3600
+ ));
3601
+ }
3589
3602
$ replacePairs = [$ escapeChar => $ escapeChar .$ escapeChar ];
3590
3603
foreach ($ this ->getLikeWildcardCharacters () as $ metaChar ) {
3591
3604
$ replacePairs [$ metaCharacter ] = $ escapeChar .$ metaChar ;
3592
3605
}
3593
3606
3594
- return strtr ($ inputString , $ replacePairs );
3595
- }
3596
-
3597
- protected function getLikeEscapeChar (): string
3598
- {
3599
- return '\\' ;
3607
+ return \strtr ($ inputString , $ replacePairs );
3600
3608
}
3601
3609
3602
3610
protected function getLikeWildcardCharacters (): iterable
0 commit comments