diff --git a/NEWS b/NEWS index f0d553b3..7ba715d6 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,11 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier . Internal change ========================== +ERRATA +- PH5P is seriously broken here; it can result in fatal errors and exceptions. + If you desire to use it, please use it with the latest, PHP5-only version of + HTML Purifier. + 2.1.4, unknown release date ! DefinitionCacheFactory now can register new implementations ! CSS properties are now case-insensitive @@ -19,6 +24,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - Fix bug with trusted script handling in libxml versions later than 2.6.28. - Fix bug in comment parsing with DirectLex - Fix bug with rgb(0, 1, 2) color syntax with spaces inside shorthand syntax +- HTMLPurifier_HTMLDefinition->addAttribute can now be called multiple times + on the same element without emitting errors. 2.1.3, released 2007-11-05 ! tests/multitest.php allows you to test multiple versions by running diff --git a/library/HTMLPurifier/HTMLDefinition.php b/library/HTMLPurifier/HTMLDefinition.php index e13e0c62..51367ca4 100644 --- a/library/HTMLPurifier/HTMLDefinition.php +++ b/library/HTMLPurifier/HTMLDefinition.php @@ -222,6 +222,8 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition /** * Adds a custom attribute to a pre-existing element + * @note This is strictly convenience, and does not have a corresponding + * method in HTMLPurifier_HTMLModule * @param $element_name String element name to add attribute to * @param $attr_name String name of attribute * @param $def Attribute definition, can be string or object, see @@ -229,7 +231,11 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition */ function addAttribute($element_name, $attr_name, $def) { $module =& $this->getAnonymousModule(); - $element =& $module->addBlankElement($element_name); + if (!isset($module->info[$element_name])) { + $element =& $module->addBlankElement($element_name); + } else { + $element =& $module->info[$element_name]; + } $element->attr[$attr_name] = $def; } diff --git a/tests/HTMLPurifier/HTMLDefinitionTest.php b/tests/HTMLPurifier/HTMLDefinitionTest.php index 28fb28cc..e616f79e 100644 --- a/tests/HTMLPurifier/HTMLDefinitionTest.php +++ b/tests/HTMLPurifier/HTMLDefinitionTest.php @@ -87,6 +87,22 @@ a[href|title] } + function test_addAttribute_multiple() { + + $config = HTMLPurifier_Config::create(array( + 'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute_multiple' + )); + $def =& $config->getHTMLDefinition(true); + $def->addAttribute('span', 'custom', 'Enum#attribute'); + $def->addAttribute('span', 'foo', 'Text'); + + $purifier = new HTMLPurifier($config); + $input = 'Custom!'; + $output = $purifier->purify($input); + $this->assertIdentical($input, $output); + + } + function test_addElement() { $config = HTMLPurifier_Config::create(array(