diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php index 7be16b3..c15d59a 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php @@ -161,9 +161,6 @@ public function databaseType() { * @throws \Drupal\Core\Database\DatabaseNotFoundException */ public function createDatabase($database) { - // Escape the database name. - $database = Database::getConnection()->escapeDatabase($database); - try { // Create the database and set it as active. $this->connection->exec("CREATE DATABASE $database"); diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php index 714dd2c..ca5017f 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php @@ -62,9 +62,15 @@ protected function connect() { Database::addConnectionInfo('default', 'default', $connection_info['default']); try { - // Now, attempt the connection again; if it's successful, attempt to - // create the database. - Database::getConnection()->createDatabase($database); + // Now attempt the connection again. If successful, check if the given + // database name is valid for creation. + $create_database = Database::getConnection()->escapeDatabase($database); + if ($create_database != $database) { + $this->fail(t("Database %database not found. The database also can't be created because in the name only alphanumeric characters and underscores are allowed.", array('%database' => $database))); + return FALSE; + } + // If it is, attempt to create the database. + Database::getConnection()->createDatabase($create_database); } catch (DatabaseNotFoundException $e) { // Still no dice; probably a permission issue. Raise the error to the diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php index 9b9cf97..a9eca95 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -200,9 +200,6 @@ public function databaseType() { * @throws \Drupal\Core\Database\DatabaseNotFoundException */ public function createDatabase($database) { - // Escape the database name. - $database = Database::getConnection()->escapeDatabase($database); - // If the PECL intl extension is installed, use it to determine the proper // locale. Otherwise, fall back to en_US. if (class_exists('Locale')) { @@ -214,7 +211,7 @@ public function createDatabase($database) { try { // Create the database and set it as active. - $this->exec("CREATE DATABASE $database WITH TEMPLATE template0 ENCODING='utf8' LC_CTYPE='$locale.utf8' LC_COLLATE='$locale.utf8'"); + $this->connection->exec("CREATE DATABASE $database WITH TEMPLATE template0 ENCODING='utf8' LC_CTYPE='$locale.utf8' LC_COLLATE='$locale.utf8'"); } catch (\Exception $e) { throw new DatabaseNotFoundException($e->getMessage()); diff --git a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php index 3f9c9a5..c5057c3 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php @@ -79,9 +79,15 @@ protected function connect() { Database::addConnectionInfo('default', 'default', $connection_info['default']); try { - // Now, attempt the connection again; if it's successful, attempt to - // create the database. - Database::getConnection()->createDatabase($database); + // Now attempt the connection again. If successful, check if the given + // database name is valid for creation. + $create_database = Database::getConnection()->escapeDatabase($database); + if ($create_database != $database) { + $this->fail(t("Database %database not found. The database also can't be created because in the name only alphanumeric characters and underscores are allowed.", array('%database' => $database))); + return FALSE; + } + // If it is, attempt to create the database. + Database::getConnection()->createDatabase($create_database); Database::closeConnection(); // Now, restore the database config.