Issues

ZF-12050: formSelect optgroup syntax broken

Description

When creating optgroups, the label is also used as part of the id:


$opt_id = ' id="' . $this->view->escape($id) . '-optgroup-'
        . $this->view->escape($opt_value) . '"';

$list[] = '';

This breaks when the label contains spaces or html entities, e.g. "Waren & Fremdleistungen", both spaces and & are not allowed in ids.

Comments

Code tags added.

Confirmed. Label value is not filtered before being used in the optgroup id.


1) Zend_View_Helper_FormSelectTest::testHtml4OptGroupLabelIsProperlySantiziedBeforeUseInId
onetwo
Failed asserting that  matches PCRE pattern "/]*?id="baz-optgroup-FooBAR"[^>]*?/".

tests/Zend/View/Helper/FormSelectTest.php:347

2) Zend_View_Helper_FormSelectTest::testHtml5OptGroupLabelIsProperlySantiziedBeforeUseInId
onetwo
Failed asserting that  matches PCRE pattern "/]*?id="baz-optgroup-Foo&&BAR"[^>]*?/".

tests/Zend/View/Helper/FormSelectTest.php:365

Attached patch which corrects this behavior, according to id element rules found here: http://stackoverflow.com/a/79022

One thing to note is that the label value is escaped before being used in the id, which means {{& -> &}}. Not sure if this is the intended behavior.