diff --git a/core/modules/locale/src/Form/TranslateFilterForm.php b/core/modules/locale/src/Form/TranslateFilterForm.php
index cfa3b696e8e7800db7a8c6aac3d294f695bcf98d..f7a3d20ec1134bb59a18b512b96ac59a723dbcae 100644
--- a/core/modules/locale/src/Form/TranslateFilterForm.php
+++ b/core/modules/locale/src/Form/TranslateFilterForm.php
@@ -85,7 +85,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
     $filters = $this->translateFilters();
     foreach ($filters as $name => $filter) {
       if ($form_state->hasValue($name)) {
-        $_SESSION['locale_translate_filter'][$name] = $form_state->getValue($name);
+        $_SESSION['locale_translate_filter'][$name] = trim($form_state->getValue($name));
       }
     }
     $form_state->setRedirect('locale.translate_page');
diff --git a/core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php b/core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php
index c0c0654c5d4b6dd8be7922ddde67f8b579652a68..dee8d835164c0aea862ff24d00ca0db623171ed4 100644
--- a/core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php
+++ b/core/modules/locale/tests/src/Functional/LocaleTranslationUiTest.php
@@ -81,10 +81,13 @@ public function testStringTranslation() {
     $this->assertText(t($name), 'Test language added.');
     $this->drupalLogout();
 
+    // Add a whitespace at the end of string to ensure it is found.
+    $name_ws = $name . " ";
+
     // Search for the name and translate it.
     $this->drupalLogin($translate_user);
     $search = [
-      'string' => $name,
+      'string' => $name_ws,
       'langcode' => $langcode,
       'translation' => 'untranslated',
     ];