diff --git a/docs/progress.html b/docs/progress.html index 44d0c111..c6c76c4e 100644 --- a/docs/progress.html +++ b/docs/progress.html @@ -133,19 +133,19 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;} Standard -background-colorCOMPOSITE(<color>, transparent) +background-colorCOMPOSITE(<color>, transparent) backgroundSHORTHAND borderSHORTHAND, MULTIPLE border-colorMULTIPLE border-styleMULTIPLE border-widthMULTIPLE border-*SHORTHAND -border-*-colorCOMPOSITE(<color>, transparent) +border-*-colorCOMPOSITE(<color>, transparent) border-*-styleENUM(none, hidden, dotted, dashed, solid, double, groove, ridge, inset, outset) border-*-widthCOMPOSITE(<length>, thin, medium, thick) clearENUM(none, left, right, both) -color<color> +color<color> floatENUM(left, right, none), May require layout precautions with clear fontSHORTHAND diff --git a/library/HTMLPurifier/AttrDef/Color.php b/library/HTMLPurifier/AttrDef/Color.php new file mode 100644 index 00000000..c527b598 --- /dev/null +++ b/library/HTMLPurifier/AttrDef/Color.php @@ -0,0 +1,67 @@ + 100) $num = 100; + $new_parts[] = "$num%"; + } else { + // handle integers + if (!$type) { + $type = 'integer'; + } elseif ($type !== 'integer') { + return false; + } + $num = (int) $part; + if ($num < 0) $num = 0; + if ($num > 255) $num = 255; + $new_parts[] = (string) $num; + } + } + $new_triad = implode(',', $new_parts); + $color = "rgb($new_triad)"; + } + + return $color; + + } + +} + +?> \ No newline at end of file diff --git a/library/HTMLPurifier/AttrDef/Composite.php b/library/HTMLPurifier/AttrDef/Composite.php index bf18b31c..39efad0a 100644 --- a/library/HTMLPurifier/AttrDef/Composite.php +++ b/library/HTMLPurifier/AttrDef/Composite.php @@ -5,8 +5,8 @@ class HTMLPurifier_AttrDef_Composite extends HTMLPurifier_AttrDef var $defs; - function HTMLPurifier_AttrDef_Composite(&$defs) { - $this->defs =& $defs; + function HTMLPurifier_AttrDef_Composite($defs) { + $this->defs = $defs; } function validate($string, $config, &$context) { diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index 070aad86..f296fd76 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -43,6 +43,16 @@ class HTMLPurifier_CSSDefinition 'upper-roman', 'lower-alpha', 'upper-alpha'), false); $this->info['text-transform'] = new HTMLPurifier_AttrDef_Enum( array('capitalize', 'uppercase', 'lowercase', 'none'), false); + $this->info['color'] = new HTMLPurifier_AttrDef_Color(); + + $this->info['border-top-color'] = + $this->info['border-bottom-color'] = + $this->info['border-left-color'] = + $this->info['border-right-color'] = + $this->info['background-color'] = new HTMLPurifier_AttrDef_Composite( array( + new HTMLPurifier_AttrDef_Enum(array('transparent')), + new HTMLPurifier_AttrDef_Color() + )); // this could use specialized code $this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum( diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index b23b0a7f..ab46d142 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -20,6 +20,10 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness $this->assertDef('list-style-position:outside;'); $this->assertDef('list-style-type:upper-roman;'); $this->assertDef('text-transform:capitalize;'); + $this->assertDef('background-color:rgb(0,0,255);'); + $this->assertDef('background-color:transparent;'); + $this->assertDef('color:#F00;'); + $this->assertDef('border-top-color:#F00;'); // duplicates $this->assertDef('text-align:right;text-align:left;', diff --git a/tests/HTMLPurifier/AttrDef/ColorTest.php b/tests/HTMLPurifier/AttrDef/ColorTest.php new file mode 100644 index 00000000..84ddff17 --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/ColorTest.php @@ -0,0 +1,33 @@ +def = new HTMLPurifier_AttrDef_Color(); + + $this->assertDef('#F00'); + $this->assertDef('#808080'); + $this->assertDef('rgb(255, 0, 0)', 'rgb(255,0,0)'); // rm spaces + $this->assertDef('rgb(100%,0%,0%)'); + $this->assertDef('rgb(50.5%,23.2%,43.9%)'); // decimals okay + + $this->assertDef('#G00', false); + $this->assertDef('cmyk(40, 23, 43, 23)', false); + $this->assertDef('rgb(0%, 23, 68%)', false); + + // clip numbers outside sRGB gamut + $this->assertDef('rgb(200%, -10%, 0%)', 'rgb(100%,0%,0%)'); + $this->assertDef('rgb(256,-23,34)', 'rgb(255,0,34)'); + + // maybe hex transformations would be another nice feature + // at the very least transform rgb percent to rgb integer + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/CompositeTest.php b/tests/HTMLPurifier/AttrDef/CompositeTest.php index bd81db60..adc520a2 100644 --- a/tests/HTMLPurifier/AttrDef/CompositeTest.php +++ b/tests/HTMLPurifier/AttrDef/CompositeTest.php @@ -2,6 +2,16 @@ require_once 'HTMLPurifier/AttrDef/Composite.php'; +class HTMLPurifier_AttrDef_Composite_Testable extends + HTMLPurifier_AttrDef_Composite +{ + + function HTMLPurifier_AttrDef_Composite_Testable(&$defs) { + $this->defs =& $defs; + } + +} + class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness { @@ -20,7 +30,7 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness $def1 =& new HTMLPurifier_AttrDefMock($this); $def2 =& new HTMLPurifier_AttrDefMock($this); $defs = array(&$def1, &$def2); - $def =& new HTMLPurifier_AttrDef_Composite($defs); + $def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); $input = 'FOOBAR'; $output = 'foobar'; $def1_params = array($input, $config, $context); @@ -39,7 +49,7 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness $def1 =& new HTMLPurifier_AttrDefMock($this); $def2 =& new HTMLPurifier_AttrDefMock($this); $defs = array(&$def1, &$def2); - $def =& new HTMLPurifier_AttrDef_Composite($defs); + $def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); $input = 'BOOMA'; $output = 'booma'; $def_params = array($input, $config, $context); @@ -59,7 +69,7 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness $def1 =& new HTMLPurifier_AttrDefMock($this); $def2 =& new HTMLPurifier_AttrDefMock($this); $defs = array(&$def1, &$def2); - $def =& new HTMLPurifier_AttrDef_Composite($defs); + $def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); $input = 'BOOMA'; $output = false; $def_params = array($input, $config, $context); diff --git a/tests/index.php b/tests/index.php index cd9d7c5d..8028446b 100644 --- a/tests/index.php +++ b/tests/index.php @@ -65,6 +65,7 @@ $test_files[] = 'AttrDef/NumberSpanTest.php'; $test_files[] = 'AttrDef/URITest.php'; $test_files[] = 'AttrDef/CSSTest.php'; $test_files[] = 'AttrDef/CompositeTest.php'; +$test_files[] = 'AttrDef/ColorTest.php'; $test_files[] = 'IDAccumulatorTest.php'; $test_files[] = 'TagTransformTest.php'; $test_files[] = 'AttrTransform/LangTest.php';