diff --git a/library/HTMLPurifier/AttrDef/Length.php b/library/HTMLPurifier/AttrDef/Length.php new file mode 100644 index 00000000..7cddb67d --- /dev/null +++ b/library/HTMLPurifier/AttrDef/Length.php @@ -0,0 +1,37 @@ + 100) return '100%'; + + return ((string) $points) . '%'; + + } + +} + +?> \ No newline at end of file diff --git a/library/HTMLPurifier/Definition.php b/library/HTMLPurifier/Definition.php index 0fe46332..a8766927 100644 --- a/library/HTMLPurifier/Definition.php +++ b/library/HTMLPurifier/Definition.php @@ -7,6 +7,7 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/AttrDef/Text.php'; require_once 'HTMLPurifier/AttrDef/Lang.php'; require_once 'HTMLPurifier/AttrDef/Pixels.php'; + require_once 'HTMLPurifier/AttrDef/Length.php'; require_once 'HTMLPurifier/AttrTransform.php'; require_once 'HTMLPurifier/AttrTransform/Lang.php'; require_once 'HTMLPurifier/AttrTransform/TextAlign.php'; @@ -243,10 +244,6 @@ class HTMLPurifier_Definition // complex attribute value substitution $e_Text = new HTMLPurifier_AttrDef_Text(); - $e_TFrame = new HTMLPurifier_AttrDef_Enum(array('void', 'above', - 'below', 'hsides', 'lhs', 'rhs', 'vsides', 'box', 'border'), false); - $e_TRules = new HTMLPurifier_AttrDef_Enum(array('none', 'groups', - 'rows', 'cols', 'all'), false); // attrs, included in almost every single one except for a few, // which manually override these in their local definitions @@ -271,34 +268,34 @@ class HTMLPurifier_Definition $this->info['td']->attr['abbr'] = $e_Text; $this->info['th']->attr['abbr'] = $e_Text; - $this->info['col']->attr['align'] = - $this->info['colgroup']->attr['align'] = - $this->info['tbody']->attr['align'] = - $this->info['td']->attr['align'] = - $this->info['tfoot']->attr['align'] = - $this->info['th']->attr['align'] = - $this->info['thead']->attr['align'] = - $this->info['tr']->attr['align'] = new HTMLPurifier_AttrDef_Enum( - array('left', 'center', 'right', 'justify', 'char'), false); + $this->setAttrForTableElements('align', new HTMLPurifier_AttrDef_Enum( + array('left', 'center', 'right', 'justify', 'char'), false)); - $this->info['col']->attr['valign'] = - $this->info['colgroup']->attr['valign'] = - $this->info['tbody']->attr['valign'] = - $this->info['td']->attr['valign'] = - $this->info['tfoot']->attr['valign'] = - $this->info['th']->attr['valign'] = - $this->info['thead']->attr['valign'] = - $this->info['tr']->attr['valign'] = new HTMLPurifier_AttrDef_Enum( - array('top', 'middle', 'bottom', 'baseline'), false); + $this->setAttrForTableElements('valign', new HTMLPurifier_AttrDef_Enum( + array('top', 'middle', 'bottom', 'baseline'), false)); $this->info['img']->attr['alt'] = $e_Text; + $e_TFrame = new HTMLPurifier_AttrDef_Enum(array('void', 'above', + 'below', 'hsides', 'lhs', 'rhs', 'vsides', 'box', 'border'), false); $this->info['table']->attr['frame'] = $e_TFrame; + + $e_TRules = new HTMLPurifier_AttrDef_Enum(array('none', 'groups', + 'rows', 'cols', 'all'), false); $this->info['table']->attr['rules'] = $e_TRules; + $this->info['table']->attr['summary'] = $e_Text; $this->info['table']->attr['border'] = new HTMLPurifier_AttrDef_Pixels(); + $e_Length = new HTMLPurifier_AttrDef_Length(); + $this->info['table']->attr['cellpadding'] = $e_Length; + $this->info['table']->attr['cellspacing'] = $e_Length; + $this->info['table']->attr['width'] = $e_Length; + $this->setAttrForTableElements('charoff', $e_Length); + $this->info['img']->attr['height'] = $e_Length; + $this->info['img']->attr['width'] = $e_Length; + ////////////////////////////////////////////////////////////////////// // UNIMP : info_tag_transform : transformations of tags @@ -346,6 +343,17 @@ class HTMLPurifier_Definition } + function setAttrForTableElements($attr, $def) { + $this->info['col']->attr[$attr] = + $this->info['colgroup']->attr[$attr] = + $this->info['tbody']->attr[$attr] = + $this->info['td']->attr[$attr] = + $this->info['tfoot']->attr[$attr] = + $this->info['th']->attr[$attr] = + $this->info['thead']->attr[$attr] = + $this->info['tr']->attr[$attr] = $def; + } + } class HTMLPurifier_ElementDef diff --git a/tests/HTMLPurifier/AttrDef/LengthTest.php b/tests/HTMLPurifier/AttrDef/LengthTest.php new file mode 100644 index 00000000..724cda58 --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/LengthTest.php @@ -0,0 +1,35 @@ +def = new HTMLPurifier_AttrDef_Length(); + } + + function test() { + + // pixel check + parent::test(); + + // percent check + $this->assertDef('25%'); + + // Firefox maintains percent, so will we + $this->assertDef('0%'); + + // 0% <= percent <= 100% + $this->assertDef('-15%', '0%'); + $this->assertDef('120%', '100%'); + + // fractional percents, apparently, aren't allowed + $this->assertDef('56.5%', '56%'); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/PixelsTest.php b/tests/HTMLPurifier/AttrDef/PixelsTest.php index ad62235b..cab43e86 100644 --- a/tests/HTMLPurifier/AttrDef/PixelsTest.php +++ b/tests/HTMLPurifier/AttrDef/PixelsTest.php @@ -6,9 +6,11 @@ require_once 'HTMLPurifier/AttrDef/Pixels.php'; class HTMLPurifier_AttrDef_PixelsTest extends HTMLPurifier_AttrDefHarness { - function test() { - + function setup() { $this->def = new HTMLPurifier_AttrDef_Pixels(); + } + + function test() { $this->assertDef('1'); $this->assertDef('0'); diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php index 17d6ba08..5b8650cb 100644 --- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php +++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php @@ -69,12 +69,16 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends // test table $inputs[13] = << + + + - + + - + +
SupercalifragilisticFiddly nameSuper-duper-price
Cell oneCarrot Humungous$500.23
HTML; diff --git a/tests/index.php b/tests/index.php index a7ee1e2b..fc326706 100644 --- a/tests/index.php +++ b/tests/index.php @@ -44,6 +44,7 @@ $test_files[] = 'AttrDef/ClassTest.php'; $test_files[] = 'AttrDef/TextTest.php'; $test_files[] = 'AttrDef/LangTest.php'; $test_files[] = 'AttrDef/PixelsTest.php'; +$test_files[] = 'AttrDef/LengthTest.php'; $test_files[] = 'IDAccumulatorTest.php'; $test_files[] = 'TagTransformTest.php'; $test_files[] = 'AttrTransform/LangTest.php';