We have a view set up with a separate field that displays the autocomplete data in a certain format. But we found that if you search with special characters such as apostrophes, the autocomplete seems to return no results.

I tracked it down to Line 132 of views_autocomplete_filters.inc. That line is as follows:

if (isset($item['value']) && strstr(drupal_strtolower($item['value']), drupal_strtolower($string))) {

First, I'm not sure why this line is here. I mean, if you search a view for $string, it should only return results with $string's value, right? But this line seems to just verify that the items actually do have this text in the value.

In my case, $item['value'] contains the HTML encoded version of $string, so they didn't match. Therefore, I modified it to this and it now works:

if (isset($item['value']) && strstr(decode_entities(drupal_strtolower($item['value'])), drupal_strtolower($string))) {

If it even makes sense to have this check for some reason I don't see, it seems helpful to add decode_entities() to make sure these things can match.

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dandaman’s picture

Attached is the patch for the issue.

OK, to test this issue, try searching for something that has HTML-encoded values in it. For ours, we were searching a title and the title had apostrophe (') in them. The result had this encoded so the strstr() function did not match.

Actually, according to the PHP manual, for this strstr() should not be used, but should be replaced with:

strpos(decode_entities(drupal_strtolower($item['value'])), drupal_strtolower($string)) !== FALSE

Maybe I'll make another patch for that.