0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-09-19 10:45:18 +00:00

[3.1.0] Fix bug with addAttribute when called multiple times on the same element

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1634 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-03-26 04:31:04 +00:00
parent 48311b3b02
commit 9f2f6c3166
4 changed files with 25 additions and 2 deletions

2
NEWS
View File

@ -46,6 +46,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
- Fix bug in comment parsing for DirectLex
- Flush output now displayed when in command line mode for unit tester
- 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.
. Plugins now get their own changelogs according to project conventions.
. Convert tokens to use instanceof, reducing memory footprint and
improving comparison speed.

1
TODO
View File

@ -46,7 +46,6 @@ NICE FEATURES
BUGS
- Style attribute height/width limiting for images
- addAttribute multiple calls with HTMLDefinition
- Support for hard-coded paths/dirname(__FILE__) in include stub and autoload
- Easy way to blacklist elements and attributes
- Investigate iconv error emitting

View File

@ -87,6 +87,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
@ -94,7 +96,11 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition
*/
public function addAttribute($element_name, $attr_name, $def) {
$module =& $this->getAnonymousModule();
if (!isset($module->info[$element_name])) {
$element =& $module->addBlankElement($element_name);
} else {
$element =& $module->info[$element_name];
}
$element->attr[$attr_name] = $def;
}

View File

@ -85,6 +85,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 = '<span custom="attribute" foo="asdf">Custom!</span>';
$output = $purifier->purify($input);
$this->assertIdentical($input, $output);
}
function test_addElement() {
$config = HTMLPurifier_Config::create(array(