If you insert an image which has a character in its alt or title text that is encoded as an entity, such as an apostrophe, every time you save the page, the ampersand part of the entity code gets encoded again.

Sample after 4 saves:

<p>This page tests encoding of HTML entities in image alt and title text.</p>
<p>For comparison, here are some textual things that should be encoded as entities...</p>
<ol>
<li>Apostrophes/Single quotes: 'Quoted text'</li>
<li>Double quotes: "Quoted text"</li>
<li>Angle brackets: 3.2 &lt; 54 and x &gt; y.</li>
<li>Ampersands: Salt &amp; pepper. Rice &amp; beans.</li>
</ol>
<p>Image with alt and title text that contains apostrophes:</p>
<p><img alt="Green grass and blue sky&amp;amp;amp;amp;amp;#039;s the limit" title="Cool pic of grass from the ant&amp;amp;amp;amp;amp;#039;s eye view" class="panopoly-image-quarter media-element file-teaser panopoly-image-quarter" src="/sites/default/files/styles/panopoly_image_quarter/public/7787881458_ebda60dbaa_b.jpg?itok=23Xan-2g" /></p>
<p>Saved once.<br />Saved twice.<br />Saved three times.<br />Saved 4 times.</p>

Comments

dsnopek’s picture

Version: 7.x-1.6 » 7.x-1.x-dev

Retesting this with the latest Panopoly Git, it still appears to be double encoding the alt and title text, however only once. Saving the node multiple times isn't causing it to encoding the entities multiple times.

However, this no longer appears to affect apostrophe's (they are no longer HTML encoded for some reason), but still does affect ampersands and greater than or less than symbols.

dsnopek’s picture

I created a patch for Media which should fix this: #2308487: Alt and Title double encoded in WYSIWYG

It could use more testing, though!

Note: this is much easier to test when you're also using the other alt/title related changes that were just committed to Panopoly with #2307007: When inserting Image in WYSIWYG, the second set of alt/title fields is ignored

dsnopek’s picture

Status: Needs review » Fixed

Got some manual testing from @cboyden on #2308487: Alt and Title double encoded in WYSIWYG!

I've committed this patch upstream. Let's see what Travis-CI says:

https://travis-ci.org/panopoly/panopoly/builds/30742296

I'd still like to get some tests done in #2308325: Write Behat test for alt/title text on images in the WYSIWYG but it's been slow going...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.