From d886ed59fd6cb1ee5903b1ef94fdd175bc0cc129 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 6 Dec 2006 22:29:08 +0000 Subject: [PATCH] [1.3.1] Standardized all attribute handling variables to attr, made it plural git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@600 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 3 +- docs/dev-naming.html | 3 +- library/HTMLPurifier/AttrTransform.php | 2 +- library/HTMLPurifier/Generator.php | 4 +- library/HTMLPurifier/HTMLDefinition.php | 6 +-- library/HTMLPurifier/Lexer/DirectLex.php | 14 +++---- .../HTMLPurifier/Strategy/MakeWellFormed.php | 4 +- .../Strategy/RemoveForeignElements.php | 8 ++-- .../Strategy/ValidateAttributes.php | 4 +- library/HTMLPurifier/TagTransform.php | 38 +++++++++---------- library/HTMLPurifier/Token.php | 23 ++++++----- library/HTMLPurifier/TokenFactory.php | 12 +++--- tests/HTMLPurifier/TokenTest.php | 12 +++--- 13 files changed, 67 insertions(+), 66 deletions(-) diff --git a/NEWS b/NEWS index aef3b2e4..11049c09 100644 --- a/NEWS +++ b/NEWS @@ -14,7 +14,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier 1.3.1, unknown release date ! Added HTMLPurifier.func.php stub for a convenient function to call the library -. Fixed bug in RemoveInvalidImg code that caused all images to be dropped +- Fixed bug in RemoveInvalidImg code that caused all images to be dropped +. Standardized all attribute handling variables to attr, made it plural 1.3.0, released 2006-11-26 # Invalid images are now removed, rather than replaced with a dud diff --git a/docs/dev-naming.html b/docs/dev-naming.html index 44200c83..57093dee 100644 --- a/docs/dev-naming.html +++ b/docs/dev-naming.html @@ -54,8 +54,9 @@ help you find the correct functionality more quickly. Here they are:

abbreviated version is more readable than the full version. Here, we list common abbreviations: diff --git a/library/HTMLPurifier/AttrTransform.php b/library/HTMLPurifier/AttrTransform.php index 416e33a2..3513669a 100644 --- a/library/HTMLPurifier/AttrTransform.php +++ b/library/HTMLPurifier/AttrTransform.php @@ -21,7 +21,7 @@ class HTMLPurifier_AttrTransform * Abstract: makes changes to the attributes dependent on multiple values. * * @param $attr Assoc array of attributes, usually from - * HTMLPurifier_Token_Tag::$attributes + * HTMLPurifier_Token_Tag::$attr * @param $config Mandatory HTMLPurifier_Config object. * @param $context Mandatory HTMLPurifier_Context object * @returns Processed attribute array. diff --git a/library/HTMLPurifier/Generator.php b/library/HTMLPurifier/Generator.php index 95d9c536..b6a9aa24 100644 --- a/library/HTMLPurifier/Generator.php +++ b/library/HTMLPurifier/Generator.php @@ -104,14 +104,14 @@ class HTMLPurifier_Generator function generateFromToken($token) { if (!isset($token->type)) return ''; if ($token->type == 'start') { - $attr = $this->generateAttributes($token->attributes); + $attr = $this->generateAttributes($token->attr); return '<' . $token->name . ($attr ? ' ' : '') . $attr . '>'; } elseif ($token->type == 'end') { return 'name . '>'; } elseif ($token->type == 'empty') { - $attr = $this->generateAttributes($token->attributes); + $attr = $this->generateAttributes($token->attr); return '<' . $token->name . ($attr ? ' ' : '') . $attr . ( $this->_xhtml ? ' /': '' ) . '>'; diff --git a/library/HTMLPurifier/HTMLDefinition.php b/library/HTMLPurifier/HTMLDefinition.php index 13f8c5ca..b182b083 100644 --- a/library/HTMLPurifier/HTMLDefinition.php +++ b/library/HTMLPurifier/HTMLDefinition.php @@ -570,9 +570,9 @@ class HTMLPurifier_HTMLDefinition } $allowed_attributes = $config->get('HTML', 'AllowedAttributes'); if (is_array($allowed_attributes)) { - foreach ($this->info_global_attr as $attr => $info) { - if (!isset($allowed_attributes["*.$attr"])) { - unset($this->info_global_attr[$attr]); + foreach ($this->info_global_attr as $attr_key => $info) { + if (!isset($allowed_attributes["*.$attr_key"])) { + unset($this->info_global_attr[$attr_key]); } } foreach ($this->info as $tag => $info) { diff --git a/library/HTMLPurifier/Lexer/DirectLex.php b/library/HTMLPurifier/Lexer/DirectLex.php index 30b56ba0..65d95a7c 100644 --- a/library/HTMLPurifier/Lexer/DirectLex.php +++ b/library/HTMLPurifier/Lexer/DirectLex.php @@ -143,18 +143,18 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer ) ); if ($attribute_string) { - $attributes = $this->parseAttributeString( - $attribute_string - , $config, $context - ); + $attr = $this->parseAttributeString( + $attribute_string + , $config, $context + ); } else { - $attributes = array(); + $attr = array(); } if ($is_self_closing) { - $array[] = new HTMLPurifier_Token_Empty($type, $attributes); + $array[] = new HTMLPurifier_Token_Empty($type, $attr); } else { - $array[] = new HTMLPurifier_Token_Start($type, $attributes); + $array[] = new HTMLPurifier_Token_Start($type, $attr); } $cursor = $position_next_gt + 1; $inside_tag = false; diff --git a/library/HTMLPurifier/Strategy/MakeWellFormed.php b/library/HTMLPurifier/Strategy/MakeWellFormed.php index 52243767..84580d3d 100644 --- a/library/HTMLPurifier/Strategy/MakeWellFormed.php +++ b/library/HTMLPurifier/Strategy/MakeWellFormed.php @@ -30,7 +30,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy $token->type == 'start' ) { $result[] = new HTMLPurifier_Token_Empty($token->name, - $token->attributes); + $token->attr); continue; } @@ -39,7 +39,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy $token->type == 'empty' ) { $result[] = new HTMLPurifier_Token_Start($token->name, - $token->attributes); + $token->attr); $result[] = new HTMLPurifier_Token_End($token->name); continue; diff --git a/library/HTMLPurifier/Strategy/RemoveForeignElements.php b/library/HTMLPurifier/Strategy/RemoveForeignElements.php index ec23b101..27caf364 100644 --- a/library/HTMLPurifier/Strategy/RemoveForeignElements.php +++ b/library/HTMLPurifier/Strategy/RemoveForeignElements.php @@ -38,19 +38,19 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy // hard-coded image special case, pre-emptively drop // if not available. Probably not abstract-able if ( $token->name == 'img' ) { - if (!isset($token->attributes['src'])) { + if (!isset($token->attr['src'])) { continue; } if (!isset($definition->info['img']->attr['src'])) { continue; } - $token->attributes['src'] = + $token->attr['src'] = $definition-> info['img']-> attr['src']-> - validate($token->attributes['src'], + validate($token->attr['src'], $config, $context); - if ($token->attributes['src'] === false) continue; + if ($token->attr['src'] === false) continue; } } elseif ( diff --git a/library/HTMLPurifier/Strategy/ValidateAttributes.php b/library/HTMLPurifier/Strategy/ValidateAttributes.php index 2924aed2..07744f80 100644 --- a/library/HTMLPurifier/Strategy/ValidateAttributes.php +++ b/library/HTMLPurifier/Strategy/ValidateAttributes.php @@ -35,7 +35,7 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy if ($token->type !== 'start' && $token->type !== 'empty') continue; // copy out attributes for easy manipulation - $attr = $token->attributes; + $attr = $token->attr; // do global transformations (pre) // nothing currently utilizes this @@ -117,7 +117,7 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy // commit changes // could interfere with flyweight implementation - $tokens[$key]->attributes = $attr; + $tokens[$key]->attr = $attr; } $context->destroy('IDAccumulator'); diff --git a/library/HTMLPurifier/TagTransform.php b/library/HTMLPurifier/TagTransform.php index ebb59d20..be0555a0 100644 --- a/library/HTMLPurifier/TagTransform.php +++ b/library/HTMLPurifier/TagTransform.php @@ -62,16 +62,16 @@ class HTMLPurifier_TagTransform_Center extends HTMLPurifier_TagTransform $new_tag = new HTMLPurifier_Token_End($this->transform_to); return $new_tag; } - $attributes = $tag->attributes; + $attr = $tag->attr; $prepend_css = 'text-align:center;'; - if (isset($attributes['style'])) { - $attributes['style'] = $prepend_css . $attributes['style']; + if (isset($attr['style'])) { + $attr['style'] = $prepend_css . $attr['style']; } else { - $attributes['style'] = $prepend_css; + $attr['style'] = $prepend_css; } $new_tag = $tag->copy(); $new_tag->name = $this->transform_to; - $new_tag->attributes = $attributes; + $new_tag->attr = $attr; return $new_tag; } } @@ -115,39 +115,39 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform return $new_tag; } - $attributes = $tag->attributes; + $attr = $tag->attr; $prepend_style = ''; // handle color transform - if (isset($attributes['color'])) { - $prepend_style .= 'color:' . $attributes['color'] . ';'; - unset($attributes['color']); + if (isset($attr['color'])) { + $prepend_style .= 'color:' . $attr['color'] . ';'; + unset($attr['color']); } // handle face transform - if (isset($attributes['face'])) { - $prepend_style .= 'font-family:' . $attributes['face'] . ';'; - unset($attributes['face']); + if (isset($attr['face'])) { + $prepend_style .= 'font-family:' . $attr['face'] . ';'; + unset($attr['face']); } // handle size transform - if (isset($attributes['size'])) { - if (isset($this->_size_lookup[$attributes['size']])) { + if (isset($attr['size'])) { + if (isset($this->_size_lookup[$attr['size']])) { $prepend_style .= 'font-size:' . - $this->_size_lookup[$attributes['size']] . ';'; + $this->_size_lookup[$attr['size']] . ';'; } - unset($attributes['size']); + unset($attr['size']); } if ($prepend_style) { - $attributes['style'] = isset($attributes['style']) ? - $prepend_style . $attributes['style'] : + $attr['style'] = isset($attr['style']) ? + $prepend_style . $attr['style'] : $prepend_style; } $new_tag = $tag->copy(); $new_tag->name = $this->transform_to; - $new_tag->attributes = $attributes; + $new_tag->attr = $attr; return $new_tag; diff --git a/library/HTMLPurifier/Token.php b/library/HTMLPurifier/Token.php index 08ade398..555e76f1 100644 --- a/library/HTMLPurifier/Token.php +++ b/library/HTMLPurifier/Token.php @@ -50,30 +50,29 @@ class HTMLPurifier_Token_Tag extends HTMLPurifier_Token // abstract /** * Associative array of the tag's attributes. */ - var $attributes = array(); + var $attr = array(); /** * Non-overloaded constructor, which lower-cases passed tag name. * - * @param $name String name. - * @param $attributes Associative array of attributes. + * @param $name String name. + * @param $attr Associative array of attributes. */ - function HTMLPurifier_Token_Tag($name, $attributes = array()) { - //if ($attributes === null) var_dump(debug_backtrace()); + function HTMLPurifier_Token_Tag($name, $attr = array()) { $this->name = ctype_lower($name) ? $name : strtolower($name); - foreach ($attributes as $key => $value) { + foreach ($attr 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]; + if (!isset($attr[$new_key])) { + $attr[$new_key] = $attr[$key]; } if ($new_key !== $key) { - unset($attributes[$key]); + unset($attr[$key]); } } } - $this->attributes = $attributes; + $this->attr = $attr; } } @@ -84,7 +83,7 @@ class HTMLPurifier_Token_Start extends HTMLPurifier_Token_Tag { var $type = 'start'; function copy() { - return new HTMLPurifier_Token_Start($this->name, $this->attributes); + return new HTMLPurifier_Token_Start($this->name, $this->attr); } } @@ -95,7 +94,7 @@ class HTMLPurifier_Token_Empty extends HTMLPurifier_Token_Tag { var $type = 'empty'; function copy() { - return new HTMLPurifier_Token_Empty($this->name, $this->attributes); + return new HTMLPurifier_Token_Empty($this->name, $this->attr); } } diff --git a/library/HTMLPurifier/TokenFactory.php b/library/HTMLPurifier/TokenFactory.php index b377490b..25cc4122 100644 --- a/library/HTMLPurifier/TokenFactory.php +++ b/library/HTMLPurifier/TokenFactory.php @@ -37,12 +37,12 @@ class HTMLPurifier_TokenFactory /** * Creates a HTMLPurifier_Token_Start. * @param $name Tag name - * @param $attribute Associative array of attributes + * @param $attr Associative array of attributes * @return Generated HTMLPurifier_Token_Start */ - public function createStart($name, $attributes = array()) { + public function createStart($name, $attr = array()) { $p = clone $this->p_start; - $p->HTMLPurifier_Token_Tag($name, $attributes); + $p->HTMLPurifier_Token_Tag($name, $attr); return $p; } @@ -60,12 +60,12 @@ class HTMLPurifier_TokenFactory /** * Creates a HTMLPurifier_Token_Empty. * @param $name Tag name - * @param $attribute Associative array of attributes + * @param $attr Associative array of attributes * @return Generated HTMLPurifier_Token_Empty */ - public function createEmpty($name, $attributes = array()) { + public function createEmpty($name, $attr = array()) { $p = clone $this->p_empty; - $p->HTMLPurifier_Token_Tag($name, $attributes); + $p->HTMLPurifier_Token_Tag($name, $attr); return $p; } diff --git a/tests/HTMLPurifier/TokenTest.php b/tests/HTMLPurifier/TokenTest.php index e3adfbfb..6c51808e 100644 --- a/tests/HTMLPurifier/TokenTest.php +++ b/tests/HTMLPurifier/TokenTest.php @@ -5,15 +5,15 @@ require_once 'HTMLPurifier/Token.php'; class HTMLPurifier_TokenTest extends UnitTestCase { - function assertTokenConstruction($name, $attributes, - $expect_name = null, $expect_attributes = null + function assertTokenConstruction($name, $attr, + $expect_name = null, $expect_attr = null ) { if ($expect_name === null) $expect_name = $name; - if ($expect_attributes === null) $expect_attributes = $attributes; - $token = new HTMLPurifier_Token_Start($name, $attributes); + if ($expect_attr === null) $expect_attr = $attr; + $token = new HTMLPurifier_Token_Start($name, $attr); - $this->assertEqual($expect_name, $token->name); - $this->assertEqual($expect_attributes, $token->attributes); + $this->assertEqual($expect_name, $token->name); + $this->assertEqual($expect_attr, $token->attr); } function testConstruct() {