Index: library/Zend/View/Helper/FormRadio.php =================================================================== --- library/Zend/View/Helper/FormRadio.php (revision 24057) +++ library/Zend/View/Helper/FormRadio.php (working copy) @@ -129,9 +129,14 @@ $endTag= '>'; } + // Set up the filter - Alnum + hyphen + underscore + require_once 'Zend/Filter/PregReplace.php'; + $pattern = @preg_match('/\pL/u', 'a') + ? '/[^\p{L}\p{N}\-\_]/u' // Unicode + : '/[^a-zA-Z0-9\-\_]/'; // No Unicode + $filter = new Zend_Filter_PregReplace($pattern, ""); + // add radio buttons to the list. - require_once 'Zend/Filter/Alnum.php'; - $filter = new Zend_Filter_Alnum(); foreach ($options as $opt_value => $opt_label) { // Should the label be escaped? Index: tests/Zend/View/Helper/FormRadioTest.php =================================================================== --- tests/Zend/View/Helper/FormRadioTest.php (revision 24057) +++ tests/Zend/View/Helper/FormRadioTest.php (working copy) @@ -403,6 +403,32 @@ $this->assertRegexp('/]*)(for="' . $id . '")/', $html); } } + + /** + * @group ZF-4191 + */ + public function testDashesShouldNotBeFilteredFromId() + { + $name = "Foo"; + $options = array( + -1 => 'Test -1', + 0 => 'Test 0', + 1 => 'Test 1' + ); + + $formRadio = new Zend_View_Helper_FormRadio(); + $formRadio->setView(new Zend_View()); + $html = $formRadio->formRadio($name, -1, null, $options); + foreach ( $options as $key=>$value ) { + $fid = "{$name}-{$key}"; + $this->assertRegExp('/]*)(for="'.$fid.'")/', $html); + $this->assertRegExp('/]*)(id="'.$fid.'")/', $html); + } + + // Assert that radio for value -1 is the selected one + $this->assertRegExp('/]*)(id="'.$name.'--1")([^>]*)(checked="checked")/', $html); + } + } // Call Zend_View_Helper_FormRadioTest::main() if this source file is executed directly.