views_handler_filter::prepare_filter_select_options() tries to convert HTML to plain-text for displaying select options. It does this in a completely bogus way:

strip_tags(decode_entities($label));

This will convert a<b into a, because the < entity is decoded before stripping the tags.

The correct way would be:

decode_entities(strip_tags($label));

But I suggest this instead, which more closely keep the intend of the markup:

trim(str_replace("\n", " ", drupal_html_to_text($value)));
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dawehner’s picture

Assigned: Unassigned » dawehner

Link to the original issue: #1413750: escaped html element in html select element of exposed filter the actual patch had the right way to to it, but i just suggested to do it the wrong way :(

Shevchuk’s picture

Any news on this issue?

dawehner’s picture

Sorry, please don't post such pointless comments. It annoys everyone. If there is an update, there is a comment.

capellic’s picture

Issue summary: View changes

I added this to a JS file in a module I created for various admin overrides. No, not the ultimate solution.

(function ($) {
  Drupal.behaviors.correct_ampersand = {
    attach: function(context, settings) {
      /** Change & back to & in select options **/
      $('select option').each(function() {
        var text = $(this).text();
        if (text.indexOf('&') >= 0) {
          text = text.replace("&", "&");          
        }
        $(this).text(text);     
      });
    }
  }
})
(jQuery);
mpdonadio’s picture

Status: Active » Needs review
FileSize
535 bytes

This issue was linked from another one I was following (https://drupal.org/comment/7082854#comment-7082854). Here is a quick patch with Damien's suggestion. It works for me, but I was having trouble coming up with a good case to check against.

brahimmouhamou’s picture

Also views_plugin_exposed_form:exposed_form_alter executes a check_plain() to convert special characters to HTML entities which leads to problems when use quotes or ampersands.

foreach ($this->view->sort as $id => $handler) {
      if ($handler->can_expose() && $handler->is_exposed()) {
        $exposed_sorts[$id] = check_plain($handler->options['expose']['label']);
      }
    }

David Castella’s picture

Hey, there is a bug into the patch #5, with this patch, you will see id and not the label.
here is a corrected version

Chris Matthews’s picture

The 3 year old patch in #8 to views_handler_filter.inc applied cleanly to the latest views 7.x-3.x-dev and if still relevant needs to be reviewed.

Chris Matthews’s picture

Assigned: dawehner » Unassigned

Unassigning @dawehner