The SELECT list for multiple products in the Add to cart form double-escapes the product title, so characters like "&" are displayed to the user incorrectly as "&".
The Form API select list builder already passes the select option values through check_plain(), so we don't need to use check_plain() when building the '#options' array.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | fixing-double-escaped-HTML-entities-1365202-3.patch | 964 bytes | willkaxu |
Comments
Comment #1
fonant commentedThe array of '#options' form a Drupal select element gets passed though check_plain() inside the form_select_options() function in includes/form.inc. So the option values should not be passed through check_plain() when defining the select form element.
The code at line 1648 to 1650 in
commerce_cart.moduleshould be changed from:to
and the code from 1676 to 1678 should similarly read as follows, without the check_plain():
Comment #2
willkaxu commentedI followed your suggestion and fixed my display issues. But I tested it in Drupal Commerce 7.x-1.x-dev, so the position of the code should be changed is different from your suggestion. I should change the code from 1731 to 1733 and the code from 1759 to 1761.
Comment #3
willkaxu commentedIt basically does the alter trick from #1, the attached patch removes the escaping in commerce_cart_add_to_cart_form().
Comment #4
mr.baileysI think this is a duplicate of #1089328: HTML entities aren't handled correctly when adding a product reference -- if I'm wrong feel free to re-open.
Comment #5
fonant commentedThey're similar in that they're both double-quoting bugs, but they're quite different places in the code.
That #1089328: HTML entities aren't handled correctly when adding a product reference is for the Product Reference drop-down selector, a field selector.
This #1365202: Add to Cart form select list double-escapes HTML entities is for the Add to Cart drop-down selector on a product display page.
The patch above is all that's needed to fix this problem. Items in a form '#options' array should NOT be passed through check_plain() as the form code does that later.
Comment #6
rszrama commentedJust to clarify, values in a select elements #options array should not be sanitized up front, but for other elements like radios and checkboxes, they should be. I've committed the code changes in the patch in #3 but added comments for developers indicating that if they alter the form to change the type of the product selector element, they are also responsible for sanitizing the values in the #options array.
Commit: http://drupalcode.org/project/commerce.git/commitdiff/bee757d