UrlHelper adds keys to unkeyed array query parameters

Created on 11 December 2019, over 5 years ago
Updated 15 August 2025, 14 days ago

When an external URL is parsed by Drupal, notably when one is entered into a Link field, any array query parameters that do not have keys will be rendered with array keys added. Drupal\Component\Utility::parse() uses parse_str() to convert the query string into $options['query'] and that's when it happens.

Steps to reproduce:

  1. Create a link field on an entity/content type
  2. Create content of that type and enter this URL into the link field:

    https://example.com/?f%5Bcollection_name_ssi%5D%5B%5D=Example
  3. Render the link field for that entity (i.e., visit the node) and inspect the value of href=""

Expected behavior:

Field will render with href="https://example.com/?f%5Bcollection_name_ssi%5D%5B%5D=Example"

Actual behavior:

Field renders with an extra 0 in the href:

https://example.com/?f%5Bcollection_name_ssi%5D%5B0%5D=Example

Edit the node, and the 0 is not in the URL field. Render the node, and the 0 appears in the markup.

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡ΊπŸ‡ΈUnited States lunk rat

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.

  • πŸ‡ΊπŸ‡ΈUnited States dcam

    #11 shows that the parsing is performed by the base system, not the Link module.

    For the record, I've run into this problem too. There's a third-party system used at work that has un-keyed query parameters. I had to tell our content editors "You can't link to it from Drupal because its URLs are incompatible with how Drupal parses them" and they had to develop workarounds for the problem like using tiny URL services.

Production build 0.71.5 2024