From eb1e4bf240eebec7f572b323e8fb04810a872aee Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Wed, 11 Jan 2017 10:23:00 -0800 Subject: [PATCH] MysqlInstaller: Restore missing function Copied from rSVN45497. I'm not sure how to reproduce the circumstances in which this code gets called, so I didn't test it. But what we did before was clearly wrong. Bug: T154670 Change-Id: Id9b0282e7e65543999c9737950f5073ba2e81962 --- includes/installer/MysqlInstaller.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/installer/MysqlInstaller.php b/includes/installer/MysqlInstaller.php index 5ff47e94f0..72697739c8 100644 --- a/includes/installer/MysqlInstaller.php +++ b/includes/installer/MysqlInstaller.php @@ -312,7 +312,7 @@ class MysqlInstaller extends DatabaseInstaller { 'IS_GRANTABLE' => 1, ], __METHOD__ ); foreach ( $res as $row ) { - $regex = $conn->likeToRegex( $row->TABLE_SCHEMA ); + $regex = $this->likeToRegex( $row->TABLE_SCHEMA ); if ( preg_match( $regex, $this->getVar( 'wgDBname' ) ) ) { unset( $grantOptions[$row->PRIVILEGE_TYPE] ); } @@ -325,6 +325,19 @@ class MysqlInstaller extends DatabaseInstaller { return true; } + /** + * Convert a wildcard (as used in LIKE) to a regex + * Slashes are escaped, slash terminators included + */ + protected function likeToRegex( $wildcard ) { + $r = preg_quote( $wildcard, '/' ); + $r = strtr( $r, [ + '%' => '.*', + '_' => '.' + ] ); + return "/$r/s"; + } + /** * @return string */ -- 2.20.1