From 9255ef8597e94935eda7735d2192e58da69e6a0d Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 5 Jan 2023 16:26:50 +0000
Subject: [PATCH] Issue #3310555 by jonathan1055, smustgrave:
 htmlspecialchars(): Passing null to parameter #1 ($string) of type string is
 deprecated

(cherry picked from commit d98f56134e5daf5fbe51f7fd279b2595e7e0279a)
---
 .../ModuleDependencyMessageTrait.php          |  2 +-
 .../src/Functional/Module/DependencyTest.php  | 22 ++++++++++++++++++-
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php b/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php
index d91085a0e68a..948e9d815225 100644
--- a/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php
+++ b/core/lib/Drupal/Core/Extension/ModuleDependencyMessageTrait.php
@@ -44,7 +44,7 @@ public function checkDependencyMessage(array $modules, $dependency, Dependency $
         $constraint_string = $dependency_object->getConstraintString();
         return $this->t('@module_name (<span class="admin-missing">incompatible with</span> version @version)', [
           '@module_name' => "$module_name ($constraint_string)",
-          '@version' => $modules[$dependency]->info['version'],
+          '@version' => $modules[$dependency]->info['version'] ?? '* ? *',
         ]);
       }
     }
diff --git a/core/modules/system/tests/src/Functional/Module/DependencyTest.php b/core/modules/system/tests/src/Functional/Module/DependencyTest.php
index ebf0b7dd8c66..fd3aa176f8da 100644
--- a/core/modules/system/tests/src/Functional/Module/DependencyTest.php
+++ b/core/modules/system/tests/src/Functional/Module/DependencyTest.php
@@ -112,16 +112,36 @@ public function testNoVersionInfo() {
     mkdir($path, 0777, TRUE);
     file_put_contents("$path/system_no_module_version_dependency_test.info.yml", Yaml::encode($info));
 
+    // Include a version in the dependency definition, to test the 'incompatible
+    // with version' message when no version is given in the required module.
     $info = [
       'type' => 'module',
       'core_version_requirement' => '*',
       'name' => 'System no module version test',
-      'dependencies' => ['system_no_module_version_dependency_test'],
+      'dependencies' => ['system_no_module_version_dependency_test(>1.x)'],
     ];
     $path = $this->siteDirectory . '/modules/system_no_module_version_test';
     mkdir($path, 0777, TRUE);
     file_put_contents("$path/system_no_module_version_test.info.yml", Yaml::encode($info));
 
+    // Ensure that the module list page is displayed without errors.
+    $this->drupalGet('admin/modules');
+    $this->assertSession()->pageTextContains('System no module version test');
+    $this->assertSession()->pageTextContains('System no module version dependency test (>1.x) (incompatible with version');
+    $this->assertSession()->fieldEnabled('modules[system_no_module_version_dependency_test][enable]');
+    $this->assertSession()->fieldDisabled('modules[system_no_module_version_test][enable]');
+
+    // Remove the version requirement from the the dependency definition
+    $info = [
+      'type' => 'module',
+      'core_version_requirement' => '*',
+      'name' => 'System no module version test',
+      'dependencies' => ['system_no_module_version_dependency_test'],
+    ];
+
+    $path = $this->siteDirectory . '/modules/system_no_module_version_test';
+    file_put_contents("$path/system_no_module_version_test.info.yml", Yaml::encode($info));
+
     $this->drupalGet('admin/modules');
     $this->assertSession()->pageTextContains('System no module version dependency test');
     $this->assertSession()->pageTextContains('System no module version test');
-- 
GitLab