From 3c431ab9842d3d902d9c7b3d21d144550b1900b3 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Tue, 14 Apr 2020 15:17:28 +0100
Subject: [PATCH] Issue #3126940 by Beakerboy, daffie: New DB URI breaks if an
 existing query part is missing the new module parameter

(cherry picked from commit d6f9e2c401a21c99792b0a4ceec8cd8c23f7d1b9)
---
 core/lib/Drupal/Core/Database/Database.php          |  2 +-
 .../Tests/Core/Database/UrlConversionTest.php       | 13 +++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Core/Database/Database.php b/core/lib/Drupal/Core/Database/Database.php
index 8a7c6147d2b8..aea70a65f106 100644
--- a/core/lib/Drupal/Core/Database/Database.php
+++ b/core/lib/Drupal/Core/Database/Database.php
@@ -468,7 +468,7 @@ public static function convertDbUrlToConnectionInfo($url, $root) {
     $url_components = parse_url($url);
     if (isset($url_components['query'])) {
       parse_str($url_components['query'], $query);
-      if ($query['module']) {
+      if (isset($query['module']) && $query['module']) {
         $module = $query['module'];
         // Set up an additional autoloader. We don't use the main autoloader as
         // this method can be called before Drupal is installed and is never
diff --git a/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php b/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php
index bc40d896e14e..883ca0f811a4 100644
--- a/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php
+++ b/core/tests/Drupal/Tests/Core/Database/UrlConversionTest.php
@@ -188,6 +188,19 @@ public function providerConvertDbUrlToConnectionInfo() {
           'autoload' => 'core/modules/system/tests/modules/driver_test/src/Driver/Database/DrivertestPgsql/',
         ],
       ],
+      'MySql with a custom query parameter' => [
+        '',
+        'mysql://test_user:test_pass@test_host:3306/test_database?extra=value',
+        [
+          'driver' => 'mysql',
+          'username' => 'test_user',
+          'password' => 'test_pass',
+          'host' => 'test_host',
+          'database' => 'test_database',
+          'port' => 3306,
+          'namespace' => 'Drupal\Core\Database\Driver\mysql',
+        ],
+      ],
     ];
   }
 
-- 
GitLab