Hello all.
I was installing D8 today and by chance I picked pre-drupal as a database name.
Then, the installer created a predupal database, but wrote pre-drupal in settings.php, so it ended with an error because it wasn't able to open the connection.

Comments

stefanosala’s picture

StatusFileSize
new1.14 KB

I worked on this patch that raise an error if you chose a name with illegal characters checked with the same regex of Connection::escapeDatabase().

Feel free to suggest a different approach if there's a better solution.

Thank you!
Stefano

stefanosala’s picture

Title: Installation - Database name gets for creation, but not for settings » Installation - Database name gets escaped for creation, but not for settings

Fixed the subject.

jhedstrom’s picture

The patch still applies, but we might need a test here, if possible.

swentel’s picture

Issue tags: +Needs tests
StatusFileSize
new1.12 KB

Rerolled. Tagging also.

jhedstrom’s picture

Issue tags: -Needs tests
StatusFileSize
new2.71 KB
new3.83 KB

I've added a unit test that tests this method. I picked the mysql implementation, but it really doesn't matter since the method being tested is on the abstract class.

The last submitted patch, 5: core-installation-2225699-05-TEST-ONLY.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: core-installation-2225699-05.patch, failed testing.

Status: Needs work » Needs review

The last submitted patch, 5: core-installation-2225699-05-TEST-ONLY.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 5: core-installation-2225699-05.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new3.83 KB
new2.71 KB

Some weird conflicts with testbot based on recent stream-wrapper commits, here's a reroll.

(Note, the TEST ONLY patch is the interdiff from #4.)

The last submitted patch, 12: core-installation-2225699-12.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 12: core-installation-2225699-12-TEST-ONLY.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new2.77 KB
new3.89 KB
new594 bytes

Argh. I should have been running the tests with the script. PHPUnit itself didn't pick up the missing namespace. The stream wrapper errors were unrelated.

The last submitted patch, 15: core-installation-2225699-15-TEST-ONLY.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 15: core-installation-2225699-15.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review

Hmm, locally the phpunit tests were passing, but I tracked that down to a views test creating the t() function. These might not be unit-testable unless we refactor the install tasks a bit to use the string translation trait.

I'm bumping this back to needs review to see what other folks think about just getting the fix in without tests.

jhedstrom’s picture

StatusFileSize
new3.11 KB
new4.22 KB
new5.43 KB

Not sure if this will be allowed, but since views does it, declaring the t() function here will get this test coverage. As mentioned above, the alternative is to us the string translation trait (but that requires quite a bit of refactoring of the install tasks--just adding the trait alone doesn't work).

The last submitted patch, 19: core-installation-2229793-19-TEST-ONLY.patch, failed testing.

nicholasruunu’s picture

+++ b/core/lib/Drupal/Core/Database/Install/Tasks.php
@@ -299,6 +299,11 @@ public function getFormOptions(array $database) {
+    // Verify database name.
+    if (preg_match('/[^A-Za-z0-9_.]+/', $database['database'])) {
+      $errors[$database['driver'] . '][database'] = t('The database name you have entered, %name, is invalid. The name can only contain alphanumeric characters or underscores.', array('%name' => $database['database']));
+    }
+

You're looking for characters which is not a dot but you're not writing that dots aren't allowed.

And I came to this issue since I realised that dots was also stripped, not only that it seemed to strip everything after the dot.
So trying to create database "example.database" ended up trying to create "example".

nicholasruunu’s picture

Priority: Normal » Critical
swentel’s picture

Priority: Critical » Normal

Normal is fine here - maybe major, but even then.

nicholasruunu’s picture

@catch recommended critical based on the behaviour I experienced, but would probably have to update this issue description.

dom.’s picture

I think, by forbidening the special characters in the database name as per #2443839: Drupal does not install when auto-creating the MySQL database with special characters, then this issue should be experienced anymore as a side-effect of not allowing special characters in DB name.

JulienD’s picture

Closing the issue because an older one is already existing #2443839

I have summarized patches and conversations over there