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
'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] );
}
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
*/