Problem/Motivation

Whitespaces at the beginning or end of text entered into an exposed filter return no results.

Steps to reproduce

Example: If you have something with "foo" and you filter for "foo" you'll get the result. But, if you filter for "foo " (with a space at the end), you'll get no result.

Proposed resolution

trim the entered text before passing to query.

Issue fork drupal-3443428

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gaurav_manerkar created an issue. See original summary.

joekers made their first commit to this issue’s fork.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

joewhitsitt made their first commit to this issue’s fork.

joewhitsitt’s picture

Status: Active » Needs review
Issue tags: +Chicago2026

Provided an MR with a test that I believe resolves this issue without causing issues for other views filtering situations.

joewhitsitt changed the visibility of the branch 3443428-whitespace-in-exposed-clean to hidden.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Bug Smash Initiative

Very nice work!

Left 1 comment on the MR around the test coverage.

joewhitsitt’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Believe feedback has been addressed for this one.

xjm’s picture

Title: Whitespace in exposed filters returns incorrect results » Whitespace in Views exposed filters returns incorrect results
xjm’s picture

I tested manually with the following steps. (Remember to document manual testing, everyone!)

  1. Install Standard from main.
  2. Create an article entitlted "Test".
  3. Edit the frontpage view to add an exposed filter on the content title.
  4. Go to the frontpage and search for test. The test article is listed in the results as expected.
  5. Repeat the search for test (with trailing space). No results.
  6. Apply the diff from this issue and clear caches.
  7. Repeat steps 4 and 5. Page is found!
xjm’s picture

Results from the test-only job:

There was 1 failure:
1) Drupal\Tests\views\Kernel\Handler\FilterStringTest::testFilterStringGroupedExposedEqual
Actual result <pre>
array (
)
</pre> is  identical to expected <pre>
array (
  0 => 
  array (
    'name' => 'Ringo',
  ),
)
</pre>
Failed asserting that two arrays are identical.
--- Expected
+++ Actual
@@ @@
-Array &0 [
-    0 => Array &1 [
-        'name' => 'Ringo',
-    ],
-]
+Array &0 []
/builds/core/modules/views/src/Tests/ViewResultAssertionTrait.php:134
/builds/core/modules/views/src/Tests/ViewResultAssertionTrait.php:33
/builds/core/modules/views/tests/src/Kernel/Handler/FilterStringTest.php:195
FAILURES!
Tests: 26, Assertions: 31, Failures: 1.
Exiting with EXIT_CODE=1

👍

xjm’s picture

I asked myself whether this bugfix was patch-safe.

It introduces:

  1. A behavior change (such that these particular searches will return results they did not before). This is a fairly edgecase thing and I think that would be fine for a backport.
  2. A method override for the string filter. This could conflict with other overrides in contrib or custom code. Therefore, that is probably minor-only, so I am going with "When in doubt, don't backport."

  • xjm committed 5a937913 on main
    fix: #3443428 Whitespace in Views exposed filters returns incorrect...

  • xjm committed 4bf4ca80 on 11.x
    fix: #3443428 Whitespace in Views exposed filters returns incorrect...
xjm’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +DevDaysAthens2026

Committed to main and 11.x as a slightly disruptive bugfix. Thanks everyone!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.