Skip to content

Commit

Permalink
[BUGFIX] Allow more characters for MySQL / MariaDB database name
Browse files Browse the repository at this point in the history
With this change it is possible to use a wider set of characters.
Please have a look at the official documentation of MySQL / MariaDB.

e.g.:

https://dev.mysql.com/doc/refman/5.5/en/identifiers.html
https://dev.mysql.com/doc/refman/5.6/en/identifiers.html
https://dev.mysql.com/doc/refman/5.7/en/identifiers.html
https://dev.mysql.com/doc/refman/8.0/en/identifiers.html
https://mariadb.com/kb/en/identifier-names/

The mentioned characters in chapter "Quoted" (ASCII and Extended) are
supported by now.

Furthermore the database name is quoted during the installation process
for creating / dropping a database.

If, for example a `.` is used in the name, a notification will be shown.

e.g.:

```
Unable to create database
Database with name "foo.test@bla123" could not be created. Either your database name contains a reserved keyword or your database user does not have sufficient permissions to create it or the database already exists. Please choose an existing (empty) database, choose another name or contact administration.
```

Resolves: #91167
Releases: master
Change-Id: I2df93f5c2238c2f0ca5ab8020ca8eebd10fdf58f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64312
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Manuel Selbach <manuel_selbach@yahoo.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Manuel Selbach <manuel_selbach@yahoo.de>
  • Loading branch information
manuelselbach committed May 12, 2020
1 parent 379288f commit d5b5b26
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
18 changes: 12 additions & 6 deletions typo3/sysext/install/Classes/Controller/InstallerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,11 @@ public function checkDatabaseRequirementsAction(ServerRequestInterface $request)
if ($success === false) {
// remove the database again if we created it
if ($request->getParsedBody()['install']['values']['type'] === 'new') {
GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME)
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
$connection
->getSchemaManager()
->dropDatabase($databaseName);
->dropDatabase($connection->quoteIdentifier($databaseName));
}

$this->configurationManager->removeLocalConfigurationKeysByPath(['DB/Connections/Default/dbname']);
Expand Down Expand Up @@ -1210,9 +1211,14 @@ protected function createNewDatabase($dbName)
$platform = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME)
->getDatabasePlatform();
GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME)
->exec(PlatformInformation::getDatabaseCreateStatementWithCharset($platform, $dbName));
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
$connection->exec(
PlatformInformation::getDatabaseCreateStatementWithCharset(
$platform,
$connection->quoteIdentifier($dbName)
)
);
$this->configurationManager
->setLocalConfigurationValueByPath('DB/Connections/Default/dbname', $dbName);
} catch (DBALException $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,31 @@ public function checkDefaultDatabaseServerCharset(Connection $connection): void
));
}
}

/**
* Validate the database name
*
* @param string $databaseName
* @return bool
*/
public static function isValidDatabaseName(string $databaseName): bool
{
return strlen($databaseName) <= static::SCHEMA_NAME_MAX_LENGTH && preg_match('/^[\x{0001}-\x{FFFF}]*$/u', $databaseName);
}

protected function checkDatabaseName(Connection $connection): void
{
if (static::isValidDatabaseName($connection->getDatabase())) {
return;
}

$this->messageQueue->enqueue(
new FlashMessage(
'The given database name must not be longer than ' . static::SCHEMA_NAME_MAX_LENGTH . ' characters'
. ' and consist of the Unicode Basic Multilingual Plane (BMP), except U+0000',
'Database name not valid',
FlashMessage::ERROR
)
);
}
}

0 comments on commit d5b5b26

Please sign in to comment.