All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Blank keywords results in php error

Ben Croker 30 Jul 2013 13:16 problem, complete

submitting the search form with the keywords field blank results in the following php error:

A PHP Error was encountered
Severity: Warning
Message: htmlspecialchars() expects parameter 1 to be string, array given
Filename: helpers/low_search_helper.php
Line Number: 346

i've changed to this which works as a temporary fix:
$str = @htmlspecialchars($str);

LS v2.3.1
EE v2.1.6

Replies

  1. Low 30 Jul 2013 16:03

    Hey Ben,

    Can't seem to replicate this. Are you sure you're using EE v2.1.6 (instead of 2.6.1)?

    Can you paste the URL that generates the error here?

  2. Ben Croker 30 Jul 2013 16:06

    yeah i meant 2.6.1

    i can't share the url publicly but will email it to you

    thanks low!

  3. Ben Croker 30 Jul 2013 16:11

    ah i forgot to mention that i'm using Publisher and this extension:
    https://github.com/litzinger/publishe...

  4. Low 30 Jul 2013 16:15

    Aha! That'll be the culprit, probably. Have you asked Brian about this?

  5. Ben Croker 30 Jul 2013 16:21

    i've asked him to take a look, will let you know what happens. thanks!

  6. Ben Croker 31 Jul 2013 11:32

    brian reckons it's nothing to do with his extension. i'll use the temporary fix i have above for now.

    cheers!

  7. Ben Croker 31 Jul 2013 11:54

    hey low, i noticed this is in the code in ext.low_search.php:

    // Check return value 
    if (is_array($str) && isset($str[0]) && isset($str[1]))
    {
    // Set excerpt string to first item in array
    $str = $str[0];

    // If second item in return value, skip native creation of excerpt
    if ($str[1] === TRUE)
    {
    $row[$this->prefix.'excerpt'] = $str;
    continue;
    }
    }

    the conditional "if ($str[1] === TRUE)" throws an error since you set "$str" to be a string on the line before. can you please look into this?

  8. Low 31 Jul 2013 17:09

    Change that into this, perhaps:

    // Check return value 
    if (is_array($str) && isset($str[0]) && isset($str[1]))
    {
    // Set excerpt string to first item in array
    $tmp = $str[1];
    $str = $str[0];

    // If second item in return value, skip native creation of excerpt
    if ($tmp === TRUE)
    {
    $row[$this->prefix.'excerpt'] = $str;
    continue;
    }
    }


    I can look into it in more detail next week when I'm back from my holiday. :)

  9. Ben Croker 31 Jul 2013 19:02

    yeah i just noticed it as a bug while looking through the code. no rush at all on this, enjoy the hols!!

  10. Low 6 Sep 2013 13:57

    Ben, for a better fix (which I haven't yet added to the core) open up ext.low_search.php and look up these lines (around #323 in v2.4.1):

    $vars[$this->prefix.$key.':raw'] = $val; 
    $vars[$this->prefix.$key] = low_format($val);


    Change that to

    if (is_array($val)) continue; 
    $vars[$this->prefix.$key.':raw'] = $val;
    $vars[$this->prefix.$key] = low_format($val);

  11. Ben Croker 6 Sep 2013 14:30

    i'll try it out, thanks