I have several select option lists I must use on my forms are generated externally. Some of the options in these lists contain "&" in the value. When a form is submitted, selected options which have a "&" in the value are not stored.
I've attached a test webform node export.
Steps:
- Import provided test webform or generate webform with a select multiple component which contains options having & in the value
- Rocky & Bullwinkle|Rocky & Bullwinkle
- Moose and Squirrel|Moose and Squirrel
- View form
- Check all options
- Submit form
- View submission result via admin.
Expected result:
- All options are included in the submission.
Observed result:
- Not all options are recorded in the submission. The options containing "&" in the value are omitted.
This is also reproducible this by adding a pagebreak and navigating back and forth. When returning to the page with the select, options with "&" in the value which had been selected are cleared.
I only tested the checkbox variant of the select component. I assume other variants (radio, select, select multiple) are affected as well.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | webform-escaped_checkbox_option-7.x-3.x-914814-14.patch | 0 bytes | torotil |
| #10 | webform-escaped_checkbox_option-914814-10.patch | 2.01 KB | danchadwick |
| webform_node.txt | 2.38 KB | jwineinger |
Comments
Comment #1
jwineinger commentedbetter title
Comment #2
quicksketchThe quick solution for this is to use a key with alphanumeric characters like this:
Though I think you're right, all characters should be allowed or at least we should add validation to prevent problems with keys.
Comment #3
jwineinger commentedYes that is a solution but not one that works in my case. I am using a custom module that generates option lists from an external source (Salesforce). Thus, I have no control over the options provided. Validation wouldn't help in this case either, since I can't do anything about their data except ask them to kindly change it (which they may not).
Comment #4
quicksketchThis is a tricky problem. If we don't escape the value of checkboxes, then users can enter single or double quotes and cause the HTML rendering to break. According to HTML spec, the contents of a "value" attribute should be HTML encoded before displaying. So Webform's escaping is technically correct, but Drupal can't keep track of the submitted values correctly.
A good temporary solution is just to display the select component as a list, which doesn't have all the bugs of checkboxes (which are notoriously difficult to deal with). I fiddled with trying to fix this problem but didn't have much success.
Comment #5
cyberwolf commentedSubscribing.
Comment #6
quicksketchThis problem still exists in the latest 4.x version as well. Using an ampersand in the key value of a checkbox throws the "An illegal choice has been detected. Please contact the site administrator." error message.
Comment #7
danchadwick commentedComment #8
danchadwick commentedSee additional commentary in duplicate issue:
#1677880: Using special html entites like &, quote or double quote etc. as key for options of webform select component.
Comment #9
danchadwick commentedTesting the current implementation (7.x-4.3):
Edit: Hmmm. The code tags mess with line spacing in a very odd way. Oh well.
Comment #10
danchadwick commentedResearching this. Webform currently contains the following replacement for expanding checkboxes. It installs this in lieu of form_process_checkboxes().
The D6 issue where the code to remove and re-created the defaulted checkboxes:
#243839: Page Break not working in Drupal 6
The D6 issue where the escaping was added:
#354240: Answers in select fields not accepted if questions contain apostrophe AND the field accepts multiple answers
The D7 issue where the #process function is rather carefully installed to avoid conflicts with other #process functions:
#1188774: Select compoent should not directly set '#process' option for select_or_other
In my testing, this process function is entirely not needed. The escaping results in double-escaping (and hence the bug reported here). The key is placed in the 'value' attribute of the input element, and is escaped with check_plain in drupal_attributes. The value is placed in #return_value, which gets turned into the value attribute and is also escaped above.
I can't reproduce any issue with these elements already being in the form for some reason. There is a comment implying an issue with multi-page forms, but I could not reproduce any such issue. I suspect this is related to some D6 issue which is no longer needed in D7.
I've uploaded a patch which simply removes the above process function. I would like some thorough testing of difficult checkbox keys and values, and editing existing already-checked submissions. Difficult keys should include keys that need escaping, such as & and attempts to introduce XSS vulnerabilities, such as:
Comment #12
danchadwick commentedCommitted to 7.x-4.x and 8.x
Comment #14
torotil commentedI've cherry-picked this into 7.x-3.x and it will be part of the 7.x-3.23 release.
There was a merge conflict so I'm also attaching the patch.
Comment #15
torotil commented