The default #value for processed_keys in the 'search_form' is an array.
search.module -- line 1052:
$form['basic']['inline']['processed_keys'] = array('#type' => 'value', '#value' => array());

The validation function (search_form_validate in search.pages.inc) sets processed_keys to a trimmed version of the keys string. If the validation function fails to run (eg. the form is used without loading search.pages.inc), some code will get an empty array, when expecting a string.

I ran into this because I forgot to load search.pages.inc and I am using the apachesolr_search module. The apachesolr_search module form_alters in a new submit handler that expects processed_keys to always be sane.

I can't see a reason the default value of processed_keys is an array. Maybe I missed something here.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Version: 6.13 » 7.x-dev

I can't see a reason either. Should be fixed in Drupal 7 and then backported to Drupal 6.

Also, shouldn't the form function and the validate/submit functions all be together in the same file?

jhodgdon’s picture

Status: Active » Needs review
FileSize
762 bytes

Here's a quick patch to fix the processed keys default.

jhodgdon’s picture

#2: 556284.patch queued for re-testing.

douggreen’s picture

Status: Needs review » Reviewed & tested by the community

yep, that's a bug, thanks!

webchick’s picture

Hm. Is it possible to follow this down and see if it breaks anything? And if so, we should probably have a test for it. If not, and it's just purely for consistency, that's fine.

douggreen’s picture

This won't throw an error because it's first use is in preg_match() which accepts an array(). However, we eventually return a string, so it's just confusing that the default is an array(). I don't think of any test that would catch this.

klausi’s picture

still applies.

jhodgdon’s picture

#2: 556284.patch queued for re-testing.

jhodgdon’s picture

#2: 556284.patch queued for re-testing.

jhodgdon’s picture

#2: 556284.patch queued for re-testing.

jhodgdon’s picture

Could we possibly get this committed, assuming this latest retest request passes?

jhodgdon’s picture

#2: 556284.patch queued for re-testing.

jhodgdon’s picture

Issue tags: +Quick fix

adding tag

sun’s picture

#2: 556284.patch queued for re-testing.

sun’s picture

Makes sense and doesn't look like this can be reasonably tested.

webchick’s picture

Version: 7.x-dev » 6.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Ok, Committed to HEAD.

Marking to 6.x for backport.

ufku’s picture

From a DX point of view, i think the default form handlers should be in the same file where the form is defined.

search_form is in search.module
search_form_validate is in search.pages.inc
search_form_submit is in search.pages.inc

So when you call drupal_get_form('search_form') in a custom page the default validate/submit handlers are not set and called unless you explicitly include search.pages.inc.

jhodgdon’s picture

RE #17 - that is a separate issue. If you would like to advocate for this, please file it as a separate issue. Thanks!

ufku’s picture

processed_keys are normalized by the default validator:search_form_validate. If the form and the validator were in the same file this issue wouldn't have appeared at all.
So, what i mentioned is the source of this issue.

Albert Volkman’s picture

Status: Patch (to be ported) » Needs review
FileSize
704 bytes

D6 backport.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

In the event that we are still committing things like this to Drupal 6, this should be committed.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: search_form_processed_keys-556284-d6-20.patch, failed testing.

Status: Needs work » Needs review
jhodgdon’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: search_form_processed_keys-556284-d6-20.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Reviewed & tested by the community

There's another D6 patch that is failing with these same errors. Something wrong with the bot?

jhodgdon’s picture

Version: 6.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Fixed

Talked with Gabor (the Drupal 6 branch maintainer) and D6 issues are really not being committed unless they're really essential -- we really don't have a test system for Drupal 6 and it's too dangerous. So... putting this back to D7 / fixed, even though this is a simple one-line patch.

Status: Fixed » Closed (fixed)

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