Warn about db name wildcards (#5390)

(cherry picked from commit 8c5ffa1c6107dca0ab0c8cf477a3b5422ee9f315)
This commit is contained in:
Johannes Meyer 2025-07-14 16:35:09 +02:00
parent f8b82d9472
commit 5b8c61f492
2 changed files with 25 additions and 0 deletions

View File

@ -133,6 +133,18 @@ class MigrationForm extends CompatForm
. ' that has the appropriate credentials to resolve this issue.' . ' that has the appropriate credentials to resolve this issue.'
), ),
implode(', ', $mm->getRequiredDatabasePrivileges()) implode(', ', $mm->getRequiredDatabasePrivileges())
))),
new HtmlElement('br'),
new HtmlElement('br'),
new HtmlElement('span', null, Text::create(sprintf(
$this->translate(
'The database name may contain either an underscore or a percent sign.'
. ' In MySQL these characters represent a wildcard. If part of a database name,'
. ' they might not have been escaped when manually granting privileges.'
. ' Privileges might not be detected in this case. Check the documentation and'
. ' update your grants accordingly: %s'
),
'https://dev.mysql.com/doc/refman/8.0/en/grant.html#grant-quoting'
))) )))
) )
); );

View File

@ -91,6 +91,19 @@ class DatabaseCreationPage extends Form
*/ */
public function createElements(array $formData) public function createElements(array $formData)
{ {
if ($this->config['db'] === 'mysql' && preg_match('/[_%]/', $this->config['dbname'])) {
$this->warning(sprintf(
$this->translate(
'The database name may contain either an underscore or a percent sign.'
. ' In MySQL these characters represent a wildcard. If part of a database name,'
. ' they might not have been escaped when manually granting privileges.'
. ' Privileges might not be detected in this case. Check the documentation and'
. ' update your grants accordingly: %s'
),
'https://dev.mysql.com/doc/refman/8.0/en/grant.html#grant-quoting'
));
}
$skipValidation = isset($formData['skip_validation']) && $formData['skip_validation']; $skipValidation = isset($formData['skip_validation']) && $formData['skip_validation'];
$this->addElement( $this->addElement(
'text', 'text',