From c0895d5769ff9d0d60bc020df79abdafaad89daa Mon Sep 17 00:00:00 2001 From: xjm <xjm@65776.no-reply.drupal.org> Date: Tue, 14 Nov 2023 14:35:54 -0600 Subject: [PATCH] Issue #3400485 by googletorp, nod_: LibraryDependencyResolver::getMinimalRepresentativeSubset() calculates dependencies incorrectly --- core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php | 2 +- .../Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php b/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php index 4c31c1b124ba..153801aa9028 100644 --- a/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php +++ b/core/lib/Drupal/Core/Asset/LibraryDependencyResolver.php @@ -86,7 +86,7 @@ public function getMinimalRepresentativeSubset(array $libraries) { foreach ($libraries as $library) { $with_deps = $this->getLibrariesWithDependencies([$library]); // We don't need library itself listed in the dependencies. - $all_dependencies += array_diff($with_deps, [$library]); + $all_dependencies = array_unique(array_merge($all_dependencies, array_diff($with_deps, [$library]))); } return array_values(array_diff($libraries, array_intersect($all_dependencies, $libraries))); diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php index 24f21b35b391..a8425ac20783 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDependencyResolverTest.php @@ -41,9 +41,11 @@ class LibraryDependencyResolverTest extends UnitTestCase { 'no_deps_a' => ['js' => [], 'css' => []], 'no_deps_b' => ['js' => [], 'css' => []], 'no_deps_c' => ['js' => [], 'css' => []], + 'no_deps_d' => ['js' => [], 'css' => []], 'deps_a' => ['js' => [], 'css' => [], 'dependencies' => ['test/no_deps_a']], 'deps_b' => ['js' => [], 'css' => [], 'dependencies' => ['test/no_deps_a', 'test/no_deps_b']], 'deps_c' => ['js' => [], 'css' => [], 'dependencies' => ['test/no_deps_b', 'test/no_deps_a']], + 'deps_d' => ['js' => [], 'css' => [], 'dependencies' => ['test/no_deps_d']], 'nested_deps_a' => ['js' => [], 'css' => [], 'dependencies' => ['test/deps_a']], 'nested_deps_b' => ['js' => [], 'css' => [], 'dependencies' => ['test/nested_deps_a']], 'nested_deps_c' => ['js' => [], 'css' => [], 'dependencies' => ['test/nested_deps_b']], @@ -139,6 +141,8 @@ public function providerTestGetMinimalRepresentativeSubset() { [['test/deps_b', 'test/deps_a'], ['test/deps_b', 'test/deps_a']], [['test/deps_b', 'test/deps_c'], ['test/deps_b', 'test/deps_c']], [['test/deps_c', 'test/deps_b'], ['test/deps_c', 'test/deps_b']], + [['test/deps_a', 'test/deps_d', 'test/no_deps_a'], ['test/deps_a', 'test/deps_d']], + [['test/deps_a', 'test/deps_d', 'test/no_deps_d'], ['test/deps_a', 'test/deps_d']], // Multi-level (indirect) dependencies. [['test/nested_deps_a'], ['test/nested_deps_a']], [['test/nested_deps_b'], ['test/nested_deps_b']], -- GitLab