Drupal.Views.parseQueryString returns incorrect results for queries without parameters

Created on 21 October 2024, 25 days ago

Problem/Motivation

Drupal.Views.parseQueryString() is used to create a map of query parameters existing in a given URL.
For example, if you pass the URL β€œhttps://example.org?x=1&y=2” to the function, you will get the following result:
{x: '1', y: '2'}

But if you pass an URL without any parameters to the function, you will get something like this:
{'https://example.org': ''}. If passing an empty string, you will get {'': ''}.

The function does not handle the case that there are no parameters in the given query. The string is simply passed on and mistakenly recognized as a parameter by const pairs = query.split('&');.

Steps to reproduce

Simple way using Chrome developer tools:
Open the Chrome developer tools console and enter Drupal.Views.parseQueryString('https://example.org'). This will give you the wrong result containing the given URL as key.

Proposed resolution

Update Drupal.Views.parseQueryString to immediately return if the given query string does not contain a question mark.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

views.module

Created by

πŸ‡©πŸ‡ͺGermany stborchert

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024