Url class generates duplicate query arguments in some situations

Created on 5 February 2016, over 9 years ago
Updated 18 August 2025, 7 days ago

Problem

Generating a URL with query string parameters that are numeric results in duplicated items in the query string.

Steps to reproduce

  • Install the newest version of Drupal
  • (You can just use the core Bartik theme for the following steps)
  • Add the following line to your THEMENAME.theme (or check if it's already there):
  use Drupal\Core\Url;
  • Add the following code to a THEMENAME_preprocess_node() function:
  $query['foo'][] = 'bar';
  $query['foo'][] = 'baz';
  $url = Url::fromUri('https://google.com', ['query' => $query]);
  $variables['test'] = [
      '#type' => 'link',
      '#title' => 'foo',
    ] + $url->toRenderArray();
  • And the following to your theme's node.html.twig file:
Test link is {{ test }}.

The result is:

https://google.com/?foo[0]=bar&foo[1]=baz&foo[2]=bar&foo[3]=baz
πŸ› Bug report
Status

Closed: outdated

Version

11.0 πŸ”₯

Component

render system

Created by

πŸ‡ΊπŸ‡ΈUnited States mikeker

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024