diff --git a/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php b/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php index ea8bff10d50..d87fdf1375c 100644 --- a/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php +++ b/core/lib/Drupal/Core/EventSubscriber/ActiveLinkResponseFilter.php @@ -127,6 +127,9 @@ class ActiveLinkResponseFilter implements EventSubscriberInterface { $search_key_current_path = 'data-drupal-link-system-path="' . $current_path . '"'; $search_key_front = 'data-drupal-link-system-path="<front>"'; + // Receive the query in a standardized manner. + ksort($query); + $offset = 0; // There are two distinct conditions that can make a link be marked active: // 1. A link has the current path in its 'data-drupal-link-system-path' diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php index 4d3d5075b21..8186b006080 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/ActiveLinkResponseFilterTest.php @@ -238,6 +238,19 @@ class ActiveLinkResponseFilterTest extends UnitTestCase { $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en', 'data-drupal-link-query' => ""]]; $situations[] = ['context' => $context, 'is active' => FALSE, 'attributes' => $attributes + ['hreflang' => 'en', 'data-drupal-link-query' => TRUE]]; + // Query with unsorted keys must match when the attribute is in sorted form. + $context = [ + 'path' => 'myfrontpage', + 'front' => TRUE, + 'language' => 'en', + 'query' => ['foo' => 'bar', 'baz' => 'qux'], + ]; + $attributes = [ + 'data-drupal-link-system-path' => 'myfrontpage', + 'data-drupal-link-query' => Json::encode(['baz' => 'qux', 'foo' => 'bar']), + ]; + $situations[] = ['context' => $context, 'is active' => TRUE, 'attributes' => $attributes]; + // Loop over the surrounding HTML variations. $data = []; for ($h = 0; $h < count($html); $h++) {