diff --git a/TODO.txt b/TODO.txt index 4f5f1c7d..70358cf7 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,13 +1,9 @@ Todo List Primary: - - Implement attribute validation - - Implement HTMLPurifier - -Secondary: - - Migrate all unit tests to use the lexer and generator + - (In Progress) Implement attribute validation + - Implement HTMLPurifier (trivial) Code issues: - Rename AbstractTest to Harness - - Reorganize Strategy hierarchy to minimize duplication - (?) Create a TokenFactory to prevent really long lines \ No newline at end of file diff --git a/library/HTMLPurifier/TagTransform.php b/library/HTMLPurifier/TagTransform.php index 230c348a..f11f2cef 100644 --- a/library/HTMLPurifier/TagTransform.php +++ b/library/HTMLPurifier/TagTransform.php @@ -9,21 +9,6 @@ class HTMLPurifier_TagTransform trigger_error('Call to abstract function', E_USER_ERROR); } - function normalizeAttributes($attributes) { - $keys = array_keys($attributes); - foreach ($keys as $key) { - // normalization only necessary when key is not lowercase - if (!ctype_lower($key)) { - $new_key = strtolower($key); - if (!isset($attributes[$new_key])) { - $attributes[$new_key] = $attributes[$key]; - } - unset($attributes[$key]); - } - } - return $attributes; - } - } class HTMLPurifier_TagTransform_Simple extends HTMLPurifier_TagTransform @@ -60,7 +45,7 @@ class HTMLPurifier_TagTransform_Simple extends HTMLPurifier_TagTransform class HTMLPurifier_TagTransform_Center extends HTMLPurifier_TagTransform { function transform($tag) { - $attributes = $this->normalizeAttributes($tag->attributes); + $attributes = $tag->attributes; $prepend_css = 'text-align:center;'; if (isset($attributes['style'])) { $attributes['style'] = $prepend_css . $attributes['style']; diff --git a/library/HTMLPurifier/Token.php b/library/HTMLPurifier/Token.php index eace6510..87e37f73 100644 --- a/library/HTMLPurifier/Token.php +++ b/library/HTMLPurifier/Token.php @@ -52,6 +52,16 @@ class HTMLPurifier_Token_Tag extends HTMLPurifier_Token // abstract */ function HTMLPurifier_Token_Tag($name, $attributes = array()) { $this->name = ctype_lower($name) ? $name : strtolower($name); + foreach ($attributes as $key => $value) { + // normalization only necessary when key is not lowercase + if (!ctype_lower($key)) { + $new_key = strtolower($key); + if (!isset($attributes[$new_key])) { + $attributes[$new_key] = $attributes[$key]; + } + unset($attributes[$key]); + } + } $this->attributes = $attributes; } } diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php index f79bdb81..3bfb4eae 100644 --- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php +++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php @@ -30,6 +30,10 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends $inputs[4] = 'Bad dir.'; $expect[4] = 'Bad dir.'; + // test case sensitivity + $inputs[5] = '
Convert ID to lowercase.
'; + $expect[5] = '
Convert ID to lowercase.
'; + $this->assertStrategyWorks($strategy, $inputs, $expect); } diff --git a/tests/HTMLPurifier/TagTransformTest.php b/tests/HTMLPurifier/TagTransformTest.php index b578abdf..44594333 100644 --- a/tests/HTMLPurifier/TagTransformTest.php +++ b/tests/HTMLPurifier/TagTransformTest.php @@ -48,18 +48,6 @@ class HTMLPurifier_TagTransformTest extends UnitTestCase } - function test_normalizeAttributes() { - - $transformer = new HTMLPurifier_TagTransform(); - - $this->assertEqual(array(), $transformer->normalizeAttributes(array())); - $this->assertEqual(array('class'=>'foo'), - $transformer->normalizeAttributes(array('class'=>'foo'))); - $this->assertEqual(array('class'=>'foo'), - $transformer->normalizeAttributes(array('CLASS'=>'foo'))); - - } - function testSimple() { $transformer = new HTMLPurifier_TagTransform_Simple('ul'); diff --git a/tests/HTMLPurifier/TokenTest.php b/tests/HTMLPurifier/TokenTest.php new file mode 100644 index 00000000..e3adfbfb --- /dev/null +++ b/tests/HTMLPurifier/TokenTest.php @@ -0,0 +1,36 @@ +assertEqual($expect_name, $token->name); + $this->assertEqual($expect_attributes, $token->attributes); + } + + function testConstruct() { + + // standard case + $this->assertTokenConstruction('a', array('href' => 'about:blank')); + + // lowercase the tag's name + $this->assertTokenConstruction('A', array('href' => 'about:blank'), + 'a'); + + // lowercase attributes + $this->assertTokenConstruction('a', array('HREF' => 'about:blank'), + 'a', array('href' => 'about:blank')); + + } + +} + +?> \ No newline at end of file