Improper display of ampersand (&) in select list. When adding a taxonomy as a CCK field and displaying it as a "Select List", it displays as &. See screenshot attached

It displays as expected in when choosing "Checkboxes/Radios".

Comments

mh86’s picture

Status: Active » Fixed

Hi!

Thanks for your report.
There was one check_plain too much for select lists, I fixed that and committed it to the D6 dev version.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

ck9’s picture

Version: 6.x-1.0-beta3 » 6.x-1.0-rc1
Status: Closed (fixed) » Active

I have this issue in 6.x-1.0-rc1. The ampersand in select lists is rendered as &amp.

ck9’s picture

Priority: Normal » Critical

This is important any ideas please?

mh86’s picture

this may also depend on your CCK version. what version of cck are you using and is there a difference between content taxonomy beta6 and rc1?

ck9’s picture

I just tried upgrading to the latest CCK module (6.x-2.4) and the problem remains. I have Content Taxonomy 6.x-1.0-rc1. Please advise, thanks.

ck9’s picture

Now tried the 6.x dev but no difference.

ck9’s picture

Priority: Critical » Normal
StatusFileSize
new504 bytes

Out of desperation I tried editing it myself and by some miracle actually fixed it. I've attached a patch although I wrote it by hand and not sure if it follows the proper convention for patches. Either way it should be clear which line was changed.

mh86’s picture

removing check_plain is a bad idea and dangerous. additionally your patch wouldn't change anything for select list. maybe you have been adding another check_plain instead?

ck9’s picture

If the check_plain is left in then the ampersands are displayed incorrectly. I'm not sure why nobody else is having this problem.

If anyone has an alternative solution then I'd be happy to try it, but this hack allowed an otherwise ready site to go live (even if removal of the check_plain impairs security).

mh86’s picture

Status: Active » Postponed (maintainer needs more info)

I'm still wondering, why this patch changes something with select lists. The original code says:

$options[$term->tid] = ($field['widget']['type'] == 'content_taxonomy_select') ? $value : check_plain($value);

it does a check_plain for every widget (like radios/checkboxes), except for a select list.
if you remove the second check_plain it only can have effects on widget not of the type 'content_taxonomy_select'.
so, I have to ask again, which widget are you exactly using? you can see that in your field settings or in your database (table content_node_field_instance)

ck9’s picture

Version: 6.x-1.0-rc1 » 6.x-1.0-rc2
Status: Postponed (maintainer needs more info) » Active

I noticed that my select lists returned to displaying & instead of &. I just installed the latest RC2 version (without any custom patches) and the problem remains. Any ideas?

Additional info.: the problem is within an exposed views form, which is used as a block within a panels page.

The_Forum’s picture

I'm also having the same problem. I am using the select list for an exposed views filter and see the html entity instead of the ampersand character. I'm using the latest RC2 and have upgraded CCK to 2.6.

robby.smith’s picture

subscribing

xjm’s picture

The views exposed filter selector is separate from Content Taxonomy's CCK option widgets, so the problem you're experiencing might not be related to the initial issue.

I'm unable to duplicate the ampersand being rendered as & entity in the exposed filter select box. I'm using Drupal 6.16, Views 2.8, Content Taxonomy rc2, and CCK 2.6. Can you provide some steps to reproduce?

davidkronfeld’s picture

same issue here.

drupal 6.16
views 2.10
content taxonomy 1.0 rc2
content taxonomy autocomplete 1.0 rc2
content taxonomy options 1.0 rc2
content taxonomy tree 1.0 rc2
option widgets 2.6

dmetzcher’s picture

StatusFileSize
new28.82 KB

Same issue here. I see it in select dropdowns and in checkboxes displayed in exposed filters. I've attached a screenshot of a list of checkboxes.

Drupal 6.16
Content Taxonomy 6.x-1.x-dev

Alexandros78’s picture

Here is what I did to solve this:

Open the form.inc (/drupal/includes/form.inc) and change line number 1447
from:
$options .= '<option value="'. check_plain($key) .'"'. $selected .'>'. check_plain($choice) .'</option>';
to:
$options .= '<option value="'. $key .'"'. $selected .'>'. $choice .'</option>';

Hope this helps!

halmsx’s picture

hi

editing the core modules is not advisable. what i did was edit a file from this module, instead of core module.

im using drupal 6.17 and content taxonomy 6.x-1.0-rc2.

the file is 'content_taxonomy/includes/views/content_taxonomy_handler_filter_many_to_one.inc'.

the original function,

...
  function get_value_options() {
    $options = content_taxonomy_allowed_values($this->content_field);
    unset($options['']);

    $this->value_options = $options;
  }
...

add a few lines in the middle.

...
  function get_value_options() {
    $options = content_taxonomy_allowed_values($this->content_field);
    unset($options['']);

    foreach ($options AS $i => $v) {
      $options[$i] = html_entity_decode($v);
    }

    $this->value_options = $options;
  }
...

im not sure how well this works for other encoding, but this solved this same problem i having with views list dropdowns.

ck9’s picture

Status: Active » Closed (fixed)

Post 19 thanks that fixed it.

YK85’s picture

Status: Closed (fixed) » Needs review

This needs to be reviewed and committed to the Content Taxonomy module correct? Thanks

xjm’s picture

Status: Needs review » Needs work

Need a working patch with the change in #19 to test.

mstrelan’s picture

Status: Needs work » Needs review
StatusFileSize
new909 bytes

Patch of #19

YK85’s picture

Thank you for the patch!

halmsx’s picture

sorry, i dont know ho to create a patch. thanks =)

xjm’s picture

jrockowitz’s picture

Patch #23 works fine for me. Thanks.

aristeides’s picture

tested and confirmed, this should definitely be committed!!

Josh Benner’s picture

StatusFileSize
new611 bytes

Patch in #23 fixes ampersands, but leaves single quotes encoded. The attached patch is a simple revision to #23 that also decodes single quotes.

alan d.’s picture

Status: Needs review » Needs work

If I am reading this right, I think that this needs to find out if you need to decode or not. Otherwise, this could open up a security hole for checkboxes / radios [maybe...].

Anyways, this is what I have just implemented. It decides if it is a select list from the filter and passes this on.

class content_taxonomy_handler_filter_many_to_one extends content_handler_filter_many_to_one {
  var $content_field;

  // Why is this defined?
  function construct() {
    parent::construct();
  }

  function get_value_options() {
    // We know that select lists should not be sanitised, let the field widget
    // settings determine the other field types.
    $sanitize = $this->value_form_type == 'select' ? FALSE : NULL;
    $options = content_taxonomy_allowed_values($this->content_field, $sanitize);
    unset($options['']);
    $this->value_options = $options;
  }
}

function content_taxonomy_allowed_values($field, $sanitize = NULL) {
...
      //do a check_plain except for selects because form api does that
      if (!isset($sanitize)) {
        $sanitize = ($field['widget']['type'] != 'content_taxonomy_select');
      }
      $options[$term->tid] = $sanitize ? check_plain($value) : $value;
...
}

I have done this in a way that will not break the existing API, but it makes more sense to just do:

$sanitize = $this->value_form_type == 'select' ? FALSE : ($field['widget']['type'] != 'content_taxonomy_select');
$options = content_taxonomy_allowed_values($this->content_field, $sanitize);

function content_taxonomy_allowed_values($field, $sanitize = TRUE) {
...
      $options[$term->tid] = $sanitize ? check_plain($value) : $value;
...
}
NathanM’s picture

Is there any chance we could get any of these solutions committed?

marleo’s picture

Wow. Four years and no fix released?
I'm seeing this in Views exposed filter select dropdown.
It only happens with content taxonomy select field. Another vocab as checkboxes doesn't do it in the exposed filter.

Patch from #23 fixed it.

Drupal 6.24
content_taxonomy 6.x-1.0-rc2
views 2.10

JCB’s picture

I can confirm #23 worked on D6