When adding an image field using Panels and setting the formatter using this module, I get the following PHP warning:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in htmlspecialchars() (line 1571 of includes/bootstrap.inc

This is caused by the #element_validate callback on the background_image_selector form field, which uses check_plain() that expects a simple string value, not the full element array.

I'm not sure what you're trying to accomplish with this, but removing this line removes the warning.

Comments

joelstein created an issue. See original summary.

joelstein’s picture

Status: Active » Needs review
StatusFileSize
new544 bytes
alesr’s picture

Removing check_plain() is not a solution.

joelstein’s picture

Status: Active » Needs review
StatusFileSize
new1.47 KB

Well, you can't send a full element array to check_plain(), hence the warning and the issue. So we have to remove it.

However, I suspect you just want to make sure that the class is properly escaped to prevent XSS. You're already doing that, but here's a patch which consolidates efforts to use filter_xss() before sending the data to the various theme functions.

garethhallnz’s picture

I have review the code and for the most part I concur with #4.

a) I can see to reason why we need #element_validate so lets remove it.
b) Yes the main concern was XSS but removing str_ireplace() creates another issue. I think a simpler solution is to simply do a strip_tags.

Joel do you mind testing my patch?

joelstein’s picture

What issue is created by removing str_ireplace()?

garethhallnz’s picture

When a css selector looked liked this .myclass > div then the > got encoded to an html entity. Initially when I wrote the module I was under the impression filter_xss would not encode the > but just escape it .... that didn't seem to be the case in my testing; perhaps it has something todo with the field api and or ui.

As I mentioned in #5 (b) I think a simpler solution is the use php's strip tags function, this makes sense to me and there is no good reason to allow code / tags or markup in a css selector.

joelstein’s picture

strip_tags sounds good to me.

  • d7d0d6a committed on 7.x-1.x
    Issue #2598154 by joelstein, garethhallnz: Warning: htmlspecialchars()...
garethhallnz’s picture

Status: Needs review » Fixed
joelstein’s picture

Thanks!

garethhallnz’s picture

Status: Fixed » Closed (fixed)