Using Drupal 7.38 with no additional modules
Steps to reproduce:
1. Use search block and search for 2 letter string
2. Use search block again to search for a longer string. This should be done while still being in search results page
Expected behaviour:
1. Use search block with 2 letter string - get error
2. Use search block in search results page with a longer string - get new results
Current behaviour:
1. Use search block with 2 letter string - get error
2. Use search block in search results page with a longer string - get the same error (You must include at least one positive keyword with 3 characters or more.)
Note that the following scenario works fine:
1. Use search block with 3 letter string - get results
2. Use search block in search results page with another string - get new results
Comments
Comment #1
cilefen CreditAttribution: cilefen commentedI have confirmed this. I checked and Drupal 8 does not have this issue.
Comment #2
jhodgdonThat's a weird one. Thanks for reporting this!
Comment #3
Da_Cloud CreditAttribution: Da_Cloud commentedI recently received the same situation as a bug report on one of my sites and I think I've found a solution to this problem. I've added an patch and in this comment you can find the thought process behind the patch.
In short this problem occurs because the submit handler of the search block (which redirects the user to the new search request) is never triggered duo to an error with the old search request.
Say you have the following situation:
Looking through the code I noticed that the search form itself ignores step 4 of the above situation by checking if the $_POST['form_id'] variable doesn't contain the string 'search_form';
The quickest way to solve this issue would be to extend this statement to also check on the form_id 'search_block_form'.
Comment #4
Da_Cloud CreditAttribution: Da_Cloud commentedComment #5
jhodgdonThanks! That looks like the right fix.
I also tested manually. Without the patch, the described behavior happens if you use the Search block, but not if you use the Search form on the search results page. With the patch, the Search block and Search form on the search results page both work. This simple patch makes this happen. Let's get it in when we can.
I guess we should technically have an automated test for it though... but maybe not necessary?
Comment #6
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedThe fix looks very nice, but yeah I think we should have tests. Mostly because after looking through Git history, they already exist from when this was fixed in Drupal 8, so all we really have to do is backport them. See:
#1366020-29: Overhaul SearchQuery; make search redirects use GET query params for keywords
#2017095: After searching for a too-short word, original search keyword is retained in subsequent searches (an earlier issue which reported the same thing as this one)
Drupal 8 tests can be found towards the bottom of SearchBlockTest::testSearchFormBlock.
It might be considered a "Novice" task to backport those and make sure the Drupal 7 patch here makes them pass.
Comment #7
Da_Cloud CreditAttribution: Da_Cloud at INDICIA commentedI've given it a shot to try and backport the tests back to Drupal 7. Its my first hands-on experience with simpletest so please take a good look at them.
Comment #8
Da_Cloud CreditAttribution: Da_Cloud at INDICIA commentedMy bad. Completely forgot to check if the new simpletests would fail without the patch, so I found a minor issue in the tests. Below patch should be correct though.
Comment #9
cilefen CreditAttribution: cilefen commented@da_cloud One way to be sure is to post a tests-only patch along with a full patch in a single comment. Attach the tests-only patch first.
Comment #10
Da_Cloud CreditAttribution: Da_Cloud at INDICIA commentedThanks for the tip. I've added both a test-only patch containing just the simpletests and the real patch which also includes the fix below.
The test-only patch should fail on the SearchBlockTestCase specifically line 677 where it picks up an error that shouldn't be there.
Comment #12
jhodgdonNice work! This looks perfect to me, and the test bot confirms that the test fails in the expected way without the patch.
Comment #13
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedCommitted to 7.x - thanks!