When creating a feed using Views RSS Feed, titles for items are encoded correctly. When creating a feed using View RSS Feed - Fields, the titles for items are double encoded. For example:

RSS Feed: <title>This &quot;title&quot; contains quotes</title>
RSS Feed - Fields: <title>This &amp;quot;title&amp;quot; contains quotes</title>

Double encoding occurs for quotes and ampersands. I have not tested other entities.

Members fund testing for the Drupal project. Drupal Association Learn more


Christian DeLoach’s picture

I suspect the issue may be cause partly by theme.inc, line 220:
$variables['rss_feed'] = format_xml_elements(array($rss_feed));

When the title is passed to format_xml_elements() the entities in the title are already encoded. format_xml_elements() encodes the contents of each node using check_plain which likely causes the double encoding.

Any ideas?

jcisio’s picture

Status: Active » Needs review
2.41 KB

Similar issue in 6.x-1.x #779760: check_plain runs twice on title. A workaround could be hook_views_rss_item_elements_alter(). However this patch fixes it properly.

pbusch’s picture

This patch is correct, the other have wrong pathes.

jcisio’s picture

Status: Needs review » Reviewed & tested by the community

#3 is basically #2 with -p1 instead of -p6, I'm marking it as RTBC because I think pbusch also tested that patch.

Brian E. Conklin’s picture

I am experiencing this exact issue, however the patch provided does not solve the problem. I believe this post is on the right track. The one extra thing I have is the rss feed - itunes also enabled.

I have also tried using 7.x-2.x-dev and get the same results.

I'm not sure what to do next.

darrick’s picture

This patch solved this issue for me. I'm also using view_rss:itunes. I had to flush the cache after applying.

idealdesigns’s picture

I bumped into this problem where i wanted to remove html tags and html special characters so i wrote a small article
Views Rss html special characters problem

Brian E. Conklin’s picture

Thanks! That solved the problem for me perfectly.

recrit’s picture

Status: Reviewed & tested by the community » Needs work

This is a larger issue that affects more than just node title. The double escape happens for any views field handler that sanitizes it's output - ie node title, term name, text fields, node body, etc.

Below is a short term workaround that I have used until a permanent fix is available:

 * Implements hook_preprocess_views_view_views_rss().
 * - Hack to fix double escaped values when using a Views RSS which is a
 *   views field based output. Ex. node title gets sanitized in views_handler_field_node
function MYMODULE_preprocess_views_view_views_rss(&$vars) {
  if (!empty($vars['rss_feed'])) {
    $vars['rss_feed'] = strtr($vars['rss_feed'], array(
      '&amp;#039;' => '&#039;',
      '&amp;quot;' => '&quot;',
      '&amp;lt;' => '&lt;',
      '&amp;gt;' => '&gt;',
      '&amp;amp;' => '&amp;',
dogmatix’s picture

#9 is working for me. Thank you.

davidneedham’s picture

Here's another workaround for those who prefer to do this in the theme rather than a custom module. Create a template file for the title field in all views: views-view-field--title.tpl.php:

  * This template is used to print a single field in a view. It is not
  * actually used in default Views, as this is registered as a theme
  * function which has better performance. For single overrides, the
  * template is perfectly okay.
  * Variables available:
  * - $view: The view object
  * - $field: The field handler object that can process the input
  * - $row: The raw SQL result that can be used
  * - $output: The processed output that will normally be used.
  * When fetching output from the $row, this construct should be used:
  * $data = $row->{$field->field_alias}
  * The above will guarantee that you'll always get the correct data,
  * regardless of any changes in the aliasing that might happen if
  * the view is modified.
  $output = htmlspecialchars_decode($output, ENT_QUOTES);
  print $output;

Naturally you could tweak the name of the tpl.php file if you needed it to affect something other than the title, or override a particular view. Refer to Theme: Information in the Advanced fieldset within your view for a list of options.

Brian E. Conklin’s picture

Brilliant! That worked perfectly and is quite simple. Thank you for posting this solution.

maciej.zgadzaj’s picture

Status: Needs work » Fixed

This should be now fixed in the most recent 7.x-2.x-dev version, just pushed to d.o. Please clone from git repo or wait till the dev package is rebuild.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

Corrected description with code tags.

Charles Belov’s picture

Title: HTML entities in the item title are double encoded » HTML entities in the item title are double encoded for feeds using fields
Issue summary: View changes
ladybug_3777’s picture

Is there a .patch file that can be used to apply the fix that is listed in comment #13? I did see this link on the referenced site: http://cgit.drupalcode.org/views_rss/patch/?id=5ab174a44775808a35f552b9c... but it's not an actual .patch file I can run with drush or apply with the patch command. Should I just use that to make my own file or am I missing something obvious?

Rhino-new’s picture

> This should be now fixed in the most recent 7.x-2.x-dev version

I'm using the most recent 7.x-2.x-dev version and I get this issue.