diff --git a/docs/progress.html b/docs/progress.html index 2d6539cb..11560a5a 100644 --- a/docs/progress.html +++ b/docs/progress.html @@ -151,7 +151,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;} fontSHORTHAND font-familyCSS validator may complain if fallback font family not specified -font-sizeCOMPOSITE(<absolute-size>, +font-sizeCOMPOSITE(<absolute-size>, <relative-size>, <length>, <percentage>) font-styleENUM(normal, italic, oblique) font-variantENUM(normal, small-caps) diff --git a/library/HTMLPurifier/AttrDef/Percentage.php b/library/HTMLPurifier/AttrDef/Percentage.php new file mode 100644 index 00000000..9c9ba4fe --- /dev/null +++ b/library/HTMLPurifier/AttrDef/Percentage.php @@ -0,0 +1,34 @@ +number_def = new HTMLPurifier_AttrDef_Number($non_negative); + } + + function validate($string, $config, &$context) { + + $string = $this->parseCDATA($string); + + if ($string === '') return false; + $length = strlen($string); + if ($length === 1) return false; + if ($string[$length - 1] !== '%') return false; + + $number = substr($string, 0, $length - 1); + $number = $this->number_def->validate($number, $config, $context); + + if ($number === false) return false; + return "$number%"; + + } + +} + +?> \ No newline at end of file diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index 43e9439b..9ff09b78 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -77,12 +77,21 @@ class HTMLPurifier_CSSDefinition new HTMLPurifier_AttrDef_CSSLength() )); + $this->info['font-size'] = new HTMLPurifier_AttrDef_Composite(array( + new HTMLPurifier_AttrDef_Enum(array('xx-small', 'x-small', + 'small', 'medium', 'large', 'x-large', 'xx-large', + 'larger', 'smaller')), + new HTMLPurifier_AttrDef_Percentage(), + new HTMLPurifier_AttrDef_CSSLength() + )); + + + // this could use specialized code $this->info['font-weight'] = new HTMLPurifier_AttrDef_Enum( array('normal', 'bold', 'bolder', 'lighter', '100', '200', '300', '400', '500', '600', '700', '800', '900'), false); - } } diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index 3efa21f5..36eecfbb 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -31,6 +31,9 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness $this->assertDef('letter-spacing:2px;'); $this->assertDef('word-spacing:normal;'); $this->assertDef('word-spacing:3em;'); + $this->assertDef('font-size:200%;'); + $this->assertDef('font-size:larger;'); + $this->assertDef('font-size:12pt;'); // duplicates $this->assertDef('text-align:right;text-align:left;', diff --git a/tests/HTMLPurifier/AttrDef/PercentageTest.php b/tests/HTMLPurifier/AttrDef/PercentageTest.php new file mode 100644 index 00000000..166cd24f --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/PercentageTest.php @@ -0,0 +1,26 @@ +def = new HTMLPurifier_AttrDef_Percentage(); + + $this->assertDef('10%'); + $this->assertDef('1.607%'); + $this->assertDef('-567%'); + + $this->assertDef(' 100% ', '100%'); + + $this->assertDef('5', false); + $this->assertDef('asdf', false); + $this->assertDef('%', false); + + } + +} + +?> \ No newline at end of file diff --git a/tests/index.php b/tests/index.php index d8b477a9..a7a66b2b 100644 --- a/tests/index.php +++ b/tests/index.php @@ -69,6 +69,7 @@ $test_files[] = 'AttrDef/ColorTest.php'; $test_files[] = 'AttrDef/IntegerTest.php'; $test_files[] = 'AttrDef/NumberTest.php'; $test_files[] = 'AttrDef/CSSLengthTest.php'; +$test_files[] = 'AttrDef/PercentageTest.php'; $test_files[] = 'IDAccumulatorTest.php'; $test_files[] = 'TagTransformTest.php'; $test_files[] = 'AttrTransform/LangTest.php';