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.
Comment | File | Size | Author |
---|---|---|---|
#11 | apostrophefix-936188-10.patch | 778 bytes | ceiadra |
#9 | apostrophefix-936188-9.patch | 793 bytes | ceiadra |
Comments
Comment #1
hutch CreditAttribution: hutch commentedHere is something you could try in the latest dev version.
in colorbox/views/colorbox_handler_field_colorbox.inc, line 139 you will find
You could try wrapping that in check_plain like so:
If that works then let this list know so that the maintainer can do his thing ;-)
Comment #2
frjo CreditAttribution: frjo commentedThe 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:
If this work I can at least add it do the help text for the caption field.
Comment #3
hutch CreditAttribution: hutch commentedAh yes I'd forgotten about allowing HTML, perhaps addslashes() would do the trick
Comment #4
potassiumchloride CreditAttribution: potassiumchloride commentedThe 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.
Comment #5
hutch CreditAttribution: hutch commentedHave you tried what I suggested in #1 with
instead of
I don't know wether it will work or not but I *think* it might.
Comment #6
frjo CreditAttribution: frjo commentedComment #7
BrianLewisDesign CreditAttribution: BrianLewisDesign commentedAn 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.
Comment #8
BrianLewisDesign CreditAttribution: BrianLewisDesign commentedIt'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);
Comment #9
ceiadra CreditAttribution: ceiadra commentedWe had the same issue, the suggestion in post 8 worked with minor modifications. Here's the patch for review.
Comment #10
hutch CreditAttribution: hutch commentedI'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'
Comment #11
ceiadra CreditAttribution: ceiadra commentedYou're right, that's a much more elegant way of doing it.
Comment #12
frjo CreditAttribution: frjo commentedClosing old issues that doesn't seems to effect a lot of users.