diff --git a/library/HTMLPurifier/AttrDef/Class.php b/library/HTMLPurifier/AttrDef/Class.php new file mode 100644 index 00000000..c6cbe916 --- /dev/null +++ b/library/HTMLPurifier/AttrDef/Class.php @@ -0,0 +1,43 @@ + \ No newline at end of file diff --git a/library/HTMLPurifier/AttrDef/ID.php b/library/HTMLPurifier/AttrDef/ID.php index a7815027..2c90e279 100644 --- a/library/HTMLPurifier/AttrDef/ID.php +++ b/library/HTMLPurifier/AttrDef/ID.php @@ -2,6 +2,12 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/IDAccumulator.php'; + +// NOTE QUIRKY BEHAVIOR: even though this is the id processor, it +// will ignore HTMLPurifier_Config::$attr_id_blacklist: it will only +// go according to the ID accumulator. Since the accumulator is +// automatically generated, it will have already absorbed the +// blacklist. If you're hacking around, make sure you use load()! class HTMLPurifier_AttrDef_ID extends HTMLPurifier_AttrDef { diff --git a/library/HTMLPurifier/Definition.php b/library/HTMLPurifier/Definition.php index 99f67d1e..255ff4ff 100644 --- a/library/HTMLPurifier/Definition.php +++ b/library/HTMLPurifier/Definition.php @@ -237,6 +237,7 @@ class HTMLPurifier_Definition $this->info_global_attr = array( // core attrs 'id' => new HTMLPurifier_AttrDef_ID(), + 'class' => new HTMLPurifier_AttrDef_Class(), // i18n 'dir' => new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false), ); diff --git a/tests/HTMLPurifier/AttrDef/ClassTest.php b/tests/HTMLPurifier/AttrDef/ClassTest.php new file mode 100644 index 00000000..6de74351 --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/ClassTest.php @@ -0,0 +1,32 @@ +assertTrue($def->validate('valid')); + $this->assertTrue($def->validate('a0-_')); + $this->assertTrue($def->validate('-valid')); + $this->assertTrue($def->validate('_valid')); + $this->assertTrue($def->validate('double valid')); + + $this->assertFalse($def->validate('0invalid')); + $this->assertFalse($def->validate('-0')); + + // test conditional replacement + $this->assertEqual('validassoc', $def->validate('validassoc 0invalid')); + + // test whitespace leniency + $this->assertTrue('double valid', $def->validate(" double\nvalid\r")); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php index 54f92c47..e59c3927 100644 --- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php +++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php @@ -19,20 +19,22 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends $inputs[0] = ''; $expect[0] = ''; + // test ids + $inputs[1] = '