From 8e67b171764cb8e7ef113e0c08d513b43de47a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Dorado?= <victor.dorado.asensio@gmail.com> Date: Sun, 15 Dec 2024 02:15:31 +0100 Subject: [PATCH 1/2] Apply the patch from #2 --- .../Plugin/views/field/FieldPluginBase.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index 4b0e4d57fd44..fd6e04875270 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -1527,17 +1527,20 @@ protected function renderAsLink($alter, $text, $tokens) { $path = $url['path']; if (isset($url['query'])) { - // Remove query parameters that were assigned a query string replacement - // token for which there is no value available. + $raw_url = UrlHelper::parse($alter['path']); foreach ($url['query'] as $param => $val) { - if ($val == '%' . $param) { - unset($url['query'][$param]); - } - // Replace any empty query params from URL parsing with NULL. So the - // query will get built correctly with only the param key. - // @see \Drupal\Component\Utility\UrlHelper::buildQuery(). if ($val === '') { - $url['query'][$param] = NULL; + // Remove query parameters that were assigned a query string + // replacement token for which there is no value available. + if (isset($raw_url['query'][$param]) && $raw_url['query'][$param] === '{{ arguments.' . $param . ' }}') { + unset($url['query'][$param]); + } + // Replace any actual empty query param from URL parsing with NULL. So + // the query will get built correctly with only the param key. + // @see \Drupal\Component\Utility\UrlHelper::buildQuery(). + else { + $url['query'][$param] = NULL; + } } } -- GitLab From 70635edb4cc6b06f59466e0fd61566f48f46b01b Mon Sep 17 00:00:00 2001 From: Joshua Fernandes <“joshua.1234511@yahoo.in”> Date: Tue, 4 Mar 2025 15:42:10 +0530 Subject: [PATCH 2/2] Added test to check Query string parameters token replacement broken when configured param is empty. --- .../tests/src/Unit/Plugin/field/FieldPluginBaseTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php index c8795b47e6fd..406f3b62517c 100644 --- a/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php +++ b/core/modules/views/tests/src/Unit/Plugin/field/FieldPluginBaseTest.php @@ -377,6 +377,13 @@ public static function providerTestRenderAsLinkWithPathAndOptions() { $data[] = ['www.example.com', ['external' => TRUE], '<a href="http://www.example.com">value</a>']; $data[] = ['', ['external' => TRUE], 'value']; + // Test with empty query parameters. + $data[] = ['test-path', ['query' => ['foo' => '']], '<a href="/test-path?foo">value</a>']; + // Test with query parameters that have tokens. + $data[] = ['test-path', ['query' => ['foo' => '{{ arguments.foo }}']], '<a href="/test-path">value</a>']; + // Test with mixed query parameters. + $data[] = ['test-path', ['query' => ['foo' => '', 'bar' => '{{ arguments.bar }}']], '<a href="/test-path?foo">value</a>']; + return $data; } -- GitLab