Using URLSearchParams in ajax before submit can break the search

Created on 31 December 2024, about 1 month ago

Problem/Motivation

Using URLSearchParams in ajax before submit can break the search when a checkbox input has a name with a plus sign in it.

Steps to reproduce

Not sure how to present the data but in views we have a checkbox with the following html:

<input data-drupal-selector="edit-intended-population-lgbtq-inclusive" class="form-checkbox" type="checkbox" id="edit-intended-population-lgbtq-inclusive" name="intended_population[LGBTQ+ inclusive]" value="LGBTQ+ inclusive">

When this checkbox is clicked for the first time, the search parameter get added like this intended_population[LGBTQ+%20inclusive]=LGBTQ%2B%20inclusive. You will notice that the value (LGBTQ+ inclusive) is properly encoded to LGBTQ%2B%20inclusive (the plus and the space characters are all encoded) but on the key side, <code>intended_population[LGBTQ+%20inclusive] only the space character is encoded.

Proposed resolution

Implement a function to add FormData to url instead of using URLSearchParams that can sometimes have a problem with preserving the plus signs.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada nikathone Ontario

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