diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php index 9e0e65f..77cd15b 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Connection.php @@ -143,9 +143,6 @@ public function databaseType() { * @throws 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 0f09aae..7933491 100644 --- a/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/mysql/Install/Tasks.php @@ -63,9 +63,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(st("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 30e9e01..ba3428d 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Connection.php @@ -203,9 +203,6 @@ public function databaseType() { * @throws 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')) { 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 1a053c0..f8fb8c3 100644 --- a/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php +++ b/core/lib/Drupal/Core/Database/Driver/pgsql/Install/Tasks.php @@ -67,9 +67,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(st("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.