mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-31 20:01:52 +00:00
[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
This commit is contained in:
parent
cbb492c52c
commit
d886ed59fd
3
NEWS
3
NEWS
@ -14,7 +14,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
|
|
||||||
1.3.1, unknown release date
|
1.3.1, unknown release date
|
||||||
! Added HTMLPurifier.func.php stub for a convenient function to call the library
|
! 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
|
1.3.0, released 2006-11-26
|
||||||
# Invalid images are now removed, rather than replaced with a dud
|
# Invalid images are now removed, rather than replaced with a dud
|
||||||
|
@ -54,8 +54,9 @@ help you find the correct functionality more quickly. Here they are:</p>
|
|||||||
abbreviated version is more readable than the full version. Here, we
|
abbreviated version is more readable than the full version. Here, we
|
||||||
list common abbreviations:
|
list common abbreviations:
|
||||||
<ul>
|
<ul>
|
||||||
<li>Attr(s) to Attribute(s)</li>
|
<li>Attr to Attributes (note that it is plural, i.e. <code>$attr = array()</code>)</li>
|
||||||
<li>Def to Definition</li>
|
<li>Def to Definition</li>
|
||||||
|
<li><code>$ret</code> is the value to be returned in a function</li>
|
||||||
</ul>
|
</ul>
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ class HTMLPurifier_AttrTransform
|
|||||||
* Abstract: makes changes to the attributes dependent on multiple values.
|
* Abstract: makes changes to the attributes dependent on multiple values.
|
||||||
*
|
*
|
||||||
* @param $attr Assoc array of attributes, usually from
|
* @param $attr Assoc array of attributes, usually from
|
||||||
* HTMLPurifier_Token_Tag::$attributes
|
* HTMLPurifier_Token_Tag::$attr
|
||||||
* @param $config Mandatory HTMLPurifier_Config object.
|
* @param $config Mandatory HTMLPurifier_Config object.
|
||||||
* @param $context Mandatory HTMLPurifier_Context object
|
* @param $context Mandatory HTMLPurifier_Context object
|
||||||
* @returns Processed attribute array.
|
* @returns Processed attribute array.
|
||||||
|
@ -104,14 +104,14 @@ class HTMLPurifier_Generator
|
|||||||
function generateFromToken($token) {
|
function generateFromToken($token) {
|
||||||
if (!isset($token->type)) return '';
|
if (!isset($token->type)) return '';
|
||||||
if ($token->type == 'start') {
|
if ($token->type == 'start') {
|
||||||
$attr = $this->generateAttributes($token->attributes);
|
$attr = $this->generateAttributes($token->attr);
|
||||||
return '<' . $token->name . ($attr ? ' ' : '') . $attr . '>';
|
return '<' . $token->name . ($attr ? ' ' : '') . $attr . '>';
|
||||||
|
|
||||||
} elseif ($token->type == 'end') {
|
} elseif ($token->type == 'end') {
|
||||||
return '</' . $token->name . '>';
|
return '</' . $token->name . '>';
|
||||||
|
|
||||||
} elseif ($token->type == 'empty') {
|
} elseif ($token->type == 'empty') {
|
||||||
$attr = $this->generateAttributes($token->attributes);
|
$attr = $this->generateAttributes($token->attr);
|
||||||
return '<' . $token->name . ($attr ? ' ' : '') . $attr .
|
return '<' . $token->name . ($attr ? ' ' : '') . $attr .
|
||||||
( $this->_xhtml ? ' /': '' )
|
( $this->_xhtml ? ' /': '' )
|
||||||
. '>';
|
. '>';
|
||||||
|
@ -570,9 +570,9 @@ class HTMLPurifier_HTMLDefinition
|
|||||||
}
|
}
|
||||||
$allowed_attributes = $config->get('HTML', 'AllowedAttributes');
|
$allowed_attributes = $config->get('HTML', 'AllowedAttributes');
|
||||||
if (is_array($allowed_attributes)) {
|
if (is_array($allowed_attributes)) {
|
||||||
foreach ($this->info_global_attr as $attr => $info) {
|
foreach ($this->info_global_attr as $attr_key => $info) {
|
||||||
if (!isset($allowed_attributes["*.$attr"])) {
|
if (!isset($allowed_attributes["*.$attr_key"])) {
|
||||||
unset($this->info_global_attr[$attr]);
|
unset($this->info_global_attr[$attr_key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ($this->info as $tag => $info) {
|
foreach ($this->info as $tag => $info) {
|
||||||
|
@ -143,18 +143,18 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ($attribute_string) {
|
if ($attribute_string) {
|
||||||
$attributes = $this->parseAttributeString(
|
$attr = $this->parseAttributeString(
|
||||||
$attribute_string
|
$attribute_string
|
||||||
, $config, $context
|
, $config, $context
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
$attributes = array();
|
$attr = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($is_self_closing) {
|
if ($is_self_closing) {
|
||||||
$array[] = new HTMLPurifier_Token_Empty($type, $attributes);
|
$array[] = new HTMLPurifier_Token_Empty($type, $attr);
|
||||||
} else {
|
} else {
|
||||||
$array[] = new HTMLPurifier_Token_Start($type, $attributes);
|
$array[] = new HTMLPurifier_Token_Start($type, $attr);
|
||||||
}
|
}
|
||||||
$cursor = $position_next_gt + 1;
|
$cursor = $position_next_gt + 1;
|
||||||
$inside_tag = false;
|
$inside_tag = false;
|
||||||
|
@ -30,7 +30,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
|||||||
$token->type == 'start' ) {
|
$token->type == 'start' ) {
|
||||||
|
|
||||||
$result[] = new HTMLPurifier_Token_Empty($token->name,
|
$result[] = new HTMLPurifier_Token_Empty($token->name,
|
||||||
$token->attributes);
|
$token->attr);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
|||||||
$token->type == 'empty' ) {
|
$token->type == 'empty' ) {
|
||||||
|
|
||||||
$result[] = new HTMLPurifier_Token_Start($token->name,
|
$result[] = new HTMLPurifier_Token_Start($token->name,
|
||||||
$token->attributes);
|
$token->attr);
|
||||||
$result[] = new HTMLPurifier_Token_End($token->name);
|
$result[] = new HTMLPurifier_Token_End($token->name);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -38,19 +38,19 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy
|
|||||||
// hard-coded image special case, pre-emptively drop
|
// hard-coded image special case, pre-emptively drop
|
||||||
// if not available. Probably not abstract-able
|
// if not available. Probably not abstract-able
|
||||||
if ( $token->name == 'img' ) {
|
if ( $token->name == 'img' ) {
|
||||||
if (!isset($token->attributes['src'])) {
|
if (!isset($token->attr['src'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!isset($definition->info['img']->attr['src'])) {
|
if (!isset($definition->info['img']->attr['src'])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$token->attributes['src'] =
|
$token->attr['src'] =
|
||||||
$definition->
|
$definition->
|
||||||
info['img']->
|
info['img']->
|
||||||
attr['src']->
|
attr['src']->
|
||||||
validate($token->attributes['src'],
|
validate($token->attr['src'],
|
||||||
$config, $context);
|
$config, $context);
|
||||||
if ($token->attributes['src'] === false) continue;
|
if ($token->attr['src'] === false) continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
} elseif (
|
} elseif (
|
||||||
|
@ -35,7 +35,7 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
|||||||
if ($token->type !== 'start' && $token->type !== 'empty') continue;
|
if ($token->type !== 'start' && $token->type !== 'empty') continue;
|
||||||
|
|
||||||
// copy out attributes for easy manipulation
|
// copy out attributes for easy manipulation
|
||||||
$attr = $token->attributes;
|
$attr = $token->attr;
|
||||||
|
|
||||||
// do global transformations (pre)
|
// do global transformations (pre)
|
||||||
// nothing currently utilizes this
|
// nothing currently utilizes this
|
||||||
@ -117,7 +117,7 @@ class HTMLPurifier_Strategy_ValidateAttributes extends HTMLPurifier_Strategy
|
|||||||
|
|
||||||
// commit changes
|
// commit changes
|
||||||
// could interfere with flyweight implementation
|
// could interfere with flyweight implementation
|
||||||
$tokens[$key]->attributes = $attr;
|
$tokens[$key]->attr = $attr;
|
||||||
}
|
}
|
||||||
$context->destroy('IDAccumulator');
|
$context->destroy('IDAccumulator');
|
||||||
|
|
||||||
|
@ -62,16 +62,16 @@ class HTMLPurifier_TagTransform_Center extends HTMLPurifier_TagTransform
|
|||||||
$new_tag = new HTMLPurifier_Token_End($this->transform_to);
|
$new_tag = new HTMLPurifier_Token_End($this->transform_to);
|
||||||
return $new_tag;
|
return $new_tag;
|
||||||
}
|
}
|
||||||
$attributes = $tag->attributes;
|
$attr = $tag->attr;
|
||||||
$prepend_css = 'text-align:center;';
|
$prepend_css = 'text-align:center;';
|
||||||
if (isset($attributes['style'])) {
|
if (isset($attr['style'])) {
|
||||||
$attributes['style'] = $prepend_css . $attributes['style'];
|
$attr['style'] = $prepend_css . $attr['style'];
|
||||||
} else {
|
} else {
|
||||||
$attributes['style'] = $prepend_css;
|
$attr['style'] = $prepend_css;
|
||||||
}
|
}
|
||||||
$new_tag = $tag->copy();
|
$new_tag = $tag->copy();
|
||||||
$new_tag->name = $this->transform_to;
|
$new_tag->name = $this->transform_to;
|
||||||
$new_tag->attributes = $attributes;
|
$new_tag->attr = $attr;
|
||||||
return $new_tag;
|
return $new_tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,39 +115,39 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform
|
|||||||
return $new_tag;
|
return $new_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
$attributes = $tag->attributes;
|
$attr = $tag->attr;
|
||||||
$prepend_style = '';
|
$prepend_style = '';
|
||||||
|
|
||||||
// handle color transform
|
// handle color transform
|
||||||
if (isset($attributes['color'])) {
|
if (isset($attr['color'])) {
|
||||||
$prepend_style .= 'color:' . $attributes['color'] . ';';
|
$prepend_style .= 'color:' . $attr['color'] . ';';
|
||||||
unset($attributes['color']);
|
unset($attr['color']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle face transform
|
// handle face transform
|
||||||
if (isset($attributes['face'])) {
|
if (isset($attr['face'])) {
|
||||||
$prepend_style .= 'font-family:' . $attributes['face'] . ';';
|
$prepend_style .= 'font-family:' . $attr['face'] . ';';
|
||||||
unset($attributes['face']);
|
unset($attr['face']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle size transform
|
// handle size transform
|
||||||
if (isset($attributes['size'])) {
|
if (isset($attr['size'])) {
|
||||||
if (isset($this->_size_lookup[$attributes['size']])) {
|
if (isset($this->_size_lookup[$attr['size']])) {
|
||||||
$prepend_style .= 'font-size:' .
|
$prepend_style .= 'font-size:' .
|
||||||
$this->_size_lookup[$attributes['size']] . ';';
|
$this->_size_lookup[$attr['size']] . ';';
|
||||||
}
|
}
|
||||||
unset($attributes['size']);
|
unset($attr['size']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($prepend_style) {
|
if ($prepend_style) {
|
||||||
$attributes['style'] = isset($attributes['style']) ?
|
$attr['style'] = isset($attr['style']) ?
|
||||||
$prepend_style . $attributes['style'] :
|
$prepend_style . $attr['style'] :
|
||||||
$prepend_style;
|
$prepend_style;
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_tag = $tag->copy();
|
$new_tag = $tag->copy();
|
||||||
$new_tag->name = $this->transform_to;
|
$new_tag->name = $this->transform_to;
|
||||||
$new_tag->attributes = $attributes;
|
$new_tag->attr = $attr;
|
||||||
|
|
||||||
return $new_tag;
|
return $new_tag;
|
||||||
|
|
||||||
|
@ -50,30 +50,29 @@ class HTMLPurifier_Token_Tag extends HTMLPurifier_Token // abstract
|
|||||||
/**
|
/**
|
||||||
* Associative array of the tag's attributes.
|
* Associative array of the tag's attributes.
|
||||||
*/
|
*/
|
||||||
var $attributes = array();
|
var $attr = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Non-overloaded constructor, which lower-cases passed tag name.
|
* Non-overloaded constructor, which lower-cases passed tag name.
|
||||||
*
|
*
|
||||||
* @param $name String name.
|
* @param $name String name.
|
||||||
* @param $attributes Associative array of attributes.
|
* @param $attr Associative array of attributes.
|
||||||
*/
|
*/
|
||||||
function HTMLPurifier_Token_Tag($name, $attributes = array()) {
|
function HTMLPurifier_Token_Tag($name, $attr = array()) {
|
||||||
//if ($attributes === null) var_dump(debug_backtrace());
|
|
||||||
$this->name = ctype_lower($name) ? $name : strtolower($name);
|
$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
|
// normalization only necessary when key is not lowercase
|
||||||
if (!ctype_lower($key)) {
|
if (!ctype_lower($key)) {
|
||||||
$new_key = strtolower($key);
|
$new_key = strtolower($key);
|
||||||
if (!isset($attributes[$new_key])) {
|
if (!isset($attr[$new_key])) {
|
||||||
$attributes[$new_key] = $attributes[$key];
|
$attr[$new_key] = $attr[$key];
|
||||||
}
|
}
|
||||||
if ($new_key !== $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';
|
var $type = 'start';
|
||||||
function copy() {
|
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';
|
var $type = 'empty';
|
||||||
function copy() {
|
function copy() {
|
||||||
return new HTMLPurifier_Token_Empty($this->name, $this->attributes);
|
return new HTMLPurifier_Token_Empty($this->name, $this->attr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,12 +37,12 @@ class HTMLPurifier_TokenFactory
|
|||||||
/**
|
/**
|
||||||
* Creates a HTMLPurifier_Token_Start.
|
* Creates a HTMLPurifier_Token_Start.
|
||||||
* @param $name Tag name
|
* @param $name Tag name
|
||||||
* @param $attribute Associative array of attributes
|
* @param $attr Associative array of attributes
|
||||||
* @return Generated HTMLPurifier_Token_Start
|
* @return Generated HTMLPurifier_Token_Start
|
||||||
*/
|
*/
|
||||||
public function createStart($name, $attributes = array()) {
|
public function createStart($name, $attr = array()) {
|
||||||
$p = clone $this->p_start;
|
$p = clone $this->p_start;
|
||||||
$p->HTMLPurifier_Token_Tag($name, $attributes);
|
$p->HTMLPurifier_Token_Tag($name, $attr);
|
||||||
return $p;
|
return $p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,12 +60,12 @@ class HTMLPurifier_TokenFactory
|
|||||||
/**
|
/**
|
||||||
* Creates a HTMLPurifier_Token_Empty.
|
* Creates a HTMLPurifier_Token_Empty.
|
||||||
* @param $name Tag name
|
* @param $name Tag name
|
||||||
* @param $attribute Associative array of attributes
|
* @param $attr Associative array of attributes
|
||||||
* @return Generated HTMLPurifier_Token_Empty
|
* @return Generated HTMLPurifier_Token_Empty
|
||||||
*/
|
*/
|
||||||
public function createEmpty($name, $attributes = array()) {
|
public function createEmpty($name, $attr = array()) {
|
||||||
$p = clone $this->p_empty;
|
$p = clone $this->p_empty;
|
||||||
$p->HTMLPurifier_Token_Tag($name, $attributes);
|
$p->HTMLPurifier_Token_Tag($name, $attr);
|
||||||
return $p;
|
return $p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,15 +5,15 @@ require_once 'HTMLPurifier/Token.php';
|
|||||||
class HTMLPurifier_TokenTest extends UnitTestCase
|
class HTMLPurifier_TokenTest extends UnitTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
function assertTokenConstruction($name, $attributes,
|
function assertTokenConstruction($name, $attr,
|
||||||
$expect_name = null, $expect_attributes = null
|
$expect_name = null, $expect_attr = null
|
||||||
) {
|
) {
|
||||||
if ($expect_name === null) $expect_name = $name;
|
if ($expect_name === null) $expect_name = $name;
|
||||||
if ($expect_attributes === null) $expect_attributes = $attributes;
|
if ($expect_attr === null) $expect_attr = $attr;
|
||||||
$token = new HTMLPurifier_Token_Start($name, $attributes);
|
$token = new HTMLPurifier_Token_Start($name, $attr);
|
||||||
|
|
||||||
$this->assertEqual($expect_name, $token->name);
|
$this->assertEqual($expect_name, $token->name);
|
||||||
$this->assertEqual($expect_attributes, $token->attributes);
|
$this->assertEqual($expect_attr, $token->attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testConstruct() {
|
function testConstruct() {
|
||||||
|
Loading…
Reference in New Issue
Block a user