Using the custom views handler, I have added fields in place of the node title in colorbox. One of the fields is a text field, and sometimes that text contains an apostrophe. I have found that when I allow this field to be viewed in colorbox, the presence of the apostrophe breaks the content. That is, the field itself does not appear, nor do any of the other caption fields that come after this one, and the image also does not appear. The forward and backward arrows work, and the next image in the colorbox appears just fine. It appears that the apostrophe is the culprit and is somehow breaking the code so that the field and any subsequent field are not displayed. Any help appreciated. I would really like to be displaying this field as part of the caption.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hutch’s picture

Here is something you could try in the latest dev version.
in colorbox/views/colorbox_handler_field_colorbox.inc, line 139 you will find

$caption = filter_xss_admin($this->options['caption']);

You could try wrapping that in check_plain like so:

$caption = filter_xss_admin($this->options['caption']);
$caption = check_plain($caption);

If that works then let this list know so that the maintainer can do his thing ;-)

frjo’s picture

The caption allows HTML after popular demand so check_plain() is not an option.

You could try to escape the apostrophe with a backslash like this:

This doesn\'t cause a problem I hope.

If this work I can at least add it do the help text for the caption field.

hutch’s picture

Ah yes I'd forgotten about allowing HTML, perhaps addslashes() would do the trick

potassiumchloride’s picture

The problem is that the apostrophe appears in probably 100+ nodes with that field, and it is that particular field I want to display as a caption on the image. I can't go in to the text field and put a slash before each apostrophe; I am using that field elsewhere and it appears with the apostrophe without an issue. It is just in the caption of the image in Colorbox where it won't display properly.

hutch’s picture

Have you tried what I suggested in #1 with

$caption = addslashes($caption);

instead of

$caption = check_plain($caption);

I don't know wether it will work or not but I *think* it might.

frjo’s picture

Status: Active » Closed (works as designed)
BrianLewisDesign’s picture

Status: Closed (works as designed) » Active

An apostrophe ' in the image Name field breaks the Colorbox popup.
How can this be closed (works as designed)?

Backslash in Name does not work. Shows the backslash on the page, and Colorbox is still broken.
HTML entity ' in Name does not work. Shows the entity characters.
$caption = addslashes($caption); does not work.
$caption = htmlentities($caption, ENT_QUOTES); does not work.
$caption = check_plain($caption); does not work.

BrianLewisDesign’s picture

It's the opposite of what I thought. The HTML entity is already there, and that is breaking the Colorbox pop-up. And the text info is in the $token, not the $caption. You have to replace the entity with the regular character. This fixed it for me.

//[ colorbox/views/colorbox_handler_field_colorbox.inc, line 141, above $caption = strtr($caption, $tokens); ]

// Apostrophe Bug Hack
foreach($tokens as &$token) { $token = str_replace(""",'"',str_replace("'","'",$token)); }
unset($token);

$caption = strtr($caption, $tokens);

ceiadra’s picture

Version: 6.x-1.0-beta7 » 6.x-1.2
Status: Active » Needs review
FileSize
793 bytes

We had the same issue, the suggestion in post 8 worked with minor modifications. Here's the patch for review.

hutch’s picture

I've seen similar problems with tooltips, if the string is already html'ised then it probably has already been through check_plain(), but you want the apostrophes back to 'real'

$string = htmlspecialchars_decode($string, ENT_QUOTES);
ceiadra’s picture

FileSize
778 bytes

You're right, that's a much more elegant way of doing it.

frjo’s picture

Status: Needs review » Closed (won't fix)

Closing old issues that doesn't seems to effect a lot of users.