diff --git a/NEWS b/NEWS
index 9098e537..21746f6e 100644
--- a/NEWS
+++ b/NEWS
@@ -14,7 +14,10 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
+ bgcolor in td, th, tr and table
+ border in img
+ name in a and img
+ + width in td, th and hr
+ + height in td, th
+ (incomplete)
+! Support for CSS attribute 'height' added
1.5.1, unknown release date
- Fix segfault in unit test. The problem is not very reproduceable and
diff --git a/docs/dev-progress.html b/docs/dev-progress.html
index 9587739b..2099c0e8 100644
--- a/docs/dev-progress.html
+++ b/docs/dev-progress.html
@@ -151,7 +151,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
will not implement list-item, run-in (Opera only) or table (no IE);
inline-block has incomplete IE6 support and requires -moz-inline-box
for Mozilla. Unknown target milestone.
-
height | Interesting, why use it? Unknown target milestone. |
+height | Interesting, why use it? Unknown target milestone. |
list-style-image | Dangerous? |
max-height | No IE 5/6 |
min-height |
@@ -276,7 +276,7 @@ Mozilla on inside and needs -moz-outline, no IE support.
clear | BR | Near-equiv style 'clear', transform 'all' into 'both' |
compact | DL, OL, UL | Boolean, needs custom CSS class; rarely used anyway |
dir | BDO | Required, insert ltr (or configuration value) if none |
-height | TD, TH | Near-equiv style 'height', needs px suffix if original was in pixels |
+height | TD, TH | Near-equiv style 'height', needs px suffix if original was in pixels |
hspace | IMG | Near-equiv styles 'margin-top' and 'margin-bottom', needs px suffix |
lang | * | Copy value to xml:lang |
name | IMG | Turn into ID |
@@ -291,8 +291,8 @@ Mozilla on inside and needs -moz-outline, no IE support.
UL |
value | LI | Poorly supported 'counter-reset', allowed in loose, dropped in strict |
vspace | IMG | Near-equiv styles 'margin-left' and 'margin-right', needs px suffix, see hspace |
-width | HR | Near-equiv style 'width', needs px suffix if original was pixels |
- TD, TH |
+width | HR | Near-equiv style 'width', needs px suffix if original was pixels |
+ TD, TH |
diff --git a/library/HTMLPurifier/AttrTransform/Length.php b/library/HTMLPurifier/AttrTransform/Length.php
new file mode 100644
index 00000000..16d3d1d8
--- /dev/null
+++ b/library/HTMLPurifier/AttrTransform/Length.php
@@ -0,0 +1,33 @@
+name = $name;
+ $this->cssName = $css_name ? $css_name : $name;
+ }
+
+ function transform($attr, $config, &$context) {
+ if (!isset($attr[$this->name])) return $attr;
+ $length = $attr[$this->name];
+ unset($attr[$this->name]);
+ if(ctype_digit($length)) $length .= 'px';
+
+ $attr['style'] = isset($attr['style']) ? $attr['style'] : '';
+ $attr['style'] = $this->cssName . ":$length;" . $attr['style'];
+
+ return $attr;
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php
index 55f0adc9..5de49b69 100644
--- a/library/HTMLPurifier/CSSDefinition.php
+++ b/library/HTMLPurifier/CSSDefinition.php
@@ -162,7 +162,9 @@ class HTMLPurifier_CSSDefinition
new HTMLPurifier_AttrDef_CSS_Percentage()
));
- $this->info['width'] = new HTMLPurifier_AttrDef_CSS_Composite(array(
+ $this->info['width'] =
+ $this->info['height'] =
+ new HTMLPurifier_AttrDef_CSS_Composite(array(
new HTMLPurifier_AttrDef_CSS_Length(true),
new HTMLPurifier_AttrDef_CSS_Percentage(true),
new HTMLPurifier_AttrDef_Enum(array('auto'))
diff --git a/library/HTMLPurifier/HTMLModule/TransformToStrict.php b/library/HTMLPurifier/HTMLModule/TransformToStrict.php
index 08a64fa1..cdbe3733 100644
--- a/library/HTMLPurifier/HTMLModule/TransformToStrict.php
+++ b/library/HTMLPurifier/HTMLModule/TransformToStrict.php
@@ -11,6 +11,7 @@ require_once 'HTMLPurifier/AttrTransform/TextAlign.php';
require_once 'HTMLPurifier/AttrTransform/BgColor.php';
require_once 'HTMLPurifier/AttrTransform/Border.php';
require_once 'HTMLPurifier/AttrTransform/Name.php';
+require_once 'HTMLPurifier/AttrTransform/Length.php';
/**
* Proprietary module that transforms deprecated elements into Strict
@@ -24,7 +25,7 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
// we're actually modifying these elements, not defining them
var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p',
- 'blockquote', 'table', 'td', 'th', 'tr', 'img', 'a');
+ 'blockquote', 'table', 'td', 'th', 'tr', 'img', 'a', 'hr');
var $info_tag_transform = array(
// placeholders, see constructor for definitions
@@ -87,6 +88,13 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule
$this->info['img']->attr_transform_pre['name'] =
$this->info['a']->attr_transform_pre['name'] = new HTMLPurifier_AttrTransform_Name();
+ $this->info['td']->attr_transform_pre['width'] =
+ $this->info['th']->attr_transform_pre['width'] =
+ $this->info['hr']->attr_transform_pre['width'] = new HTMLPurifier_AttrTransform_Length('width');
+
+ $this->info['td']->attr_transform_pre['height'] =
+ $this->info['th']->attr_transform_pre['height'] = new HTMLPurifier_AttrTransform_Length('height');
+
}
var $defines_child_def = true;
diff --git a/tests/HTMLPurifier/AttrTransform/LengthTest.php b/tests/HTMLPurifier/AttrTransform/LengthTest.php
new file mode 100644
index 00000000..e0c9474b
--- /dev/null
+++ b/tests/HTMLPurifier/AttrTransform/LengthTest.php
@@ -0,0 +1,37 @@
+obj = new HTMLPurifier_AttrTransform_Length('width');
+ }
+
+ function test() {
+ $this->assertResult( array() );
+ $this->assertResult(
+ array('width' => '10'),
+ array('style' => 'width:10px;')
+ );
+ $this->assertResult(
+ array('width' => '10%'),
+ array('style' => 'width:10%;')
+ );
+ $this->assertResult(
+ array('width' => '10%', 'style' => 'font-weight:bold'),
+ array('style' => 'width:10%;font-weight:bold')
+ );
+ // this behavior might change
+ $this->assertResult(
+ array('width' => 'asdf'),
+ array('style' => 'width:asdf;')
+ );
+ }
+
+}
+
+?>
\ No newline at end of file
diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php
index 2ece54d4..76614f8c 100644
--- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php
+++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php
@@ -179,6 +179,12 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
array('HTML.EnableAttrID' => true)
);
+ // lengths
+ $this->assertResult(
+ ' | |
',
+ ' | |
'
+ );
+
}
}
diff --git a/tests/test_files.php b/tests/test_files.php
index 9f357bbb..2b870dca 100644
--- a/tests/test_files.php
+++ b/tests/test_files.php
@@ -38,6 +38,7 @@ $test_files[] = 'AttrTransform/BgColorTest.php';
$test_files[] = 'AttrTransform/BorderTest.php';
$test_files[] = 'AttrTransform/ImgRequiredTest.php';
$test_files[] = 'AttrTransform/LangTest.php';
+$test_files[] = 'AttrTransform/LengthTest.php';
$test_files[] = 'AttrTransform/NameTest.php';
$test_files[] = 'AttrTransform/TextAlignTest.php';
$test_files[] = 'ChildDef/ChameleonTest.php';