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] = '