From 3422378c3268100e9657ada98b170a23151b5230 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 16 Aug 2006 01:39:06 +0000 Subject: [PATCH] Implement all "Multiple" CSS properties. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@273 48356398-32a2-884e-a903-53898d9a118a --- docs/progress.html | 10 +++++----- library/HTMLPurifier/CSSDefinition.php | 18 ++++++++++++++++++ tests/HTMLPurifier/AttrDef/CSSTest.php | 5 +++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/docs/progress.html b/docs/progress.html index a5bbf2ba..20226f33 100644 --- a/docs/progress.html +++ b/docs/progress.html @@ -136,9 +136,9 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;} background-colorCOMPOSITE(<color>, transparent) backgroundSHORTHAND borderSHORTHAND, MULTIPLE -border-colorMULTIPLE -border-styleMULTIPLE -border-widthMULTIPLE +border-colorMULTIPLE +border-styleMULTIPLE +border-widthMULTIPLE border-*SHORTHAND border-*-colorCOMPOSITE(<color>, transparent) border-*-styleENUM(none, hidden, dotted, dashed, @@ -168,10 +168,10 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;} decimal, lower-roman, upper-roman, lower-alpha and upper-alpha. See also CSS 3. Mostly IE lack of support. list-styleSHORTHAND -marginMULTIPLE +marginMULTIPLE margin-*COMPOSITE(<length>, <percentage>, auto) -paddingMULTIPLE +paddingMULTIPLE padding-*COMPOSITE(<length>(positive), <percentage>(positive)) text-alignENUM(left, right, diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index 105a6797..1948734b 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -5,6 +5,7 @@ require_once 'HTMLPurifier/AttrDef/Color.php'; require_once 'HTMLPurifier/AttrDef/Composite.php'; require_once 'HTMLPurifier/AttrDef/CSSLength.php'; require_once 'HTMLPurifier/AttrDef/Percentage.php'; +require_once 'HTMLPurifier/AttrDef/Multiple.php'; class HTMLPurifier_CSSDefinition { @@ -28,12 +29,17 @@ class HTMLPurifier_CSSDefinition $this->info['text-align'] = new HTMLPurifier_AttrDef_Enum( array('left', 'right', 'center', 'justify'), false); + + $border_style = $this->info['border-bottom-style'] = $this->info['border-right-style'] = $this->info['border-left-style'] = $this->info['border-top-style'] = new HTMLPurifier_AttrDef_Enum( array('none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'), false); + + $this->info['border-style'] = new HTMLPurifier_AttrDef_Multiple($border_style); + $this->info['clear'] = new HTMLPurifier_AttrDef_Enum( array('none', 'left', 'right', 'both'), false); $this->info['float'] = new HTMLPurifier_AttrDef_Enum( @@ -51,6 +57,7 @@ class HTMLPurifier_CSSDefinition array('capitalize', 'uppercase', 'lowercase', 'none'), false); $this->info['color'] = new HTMLPurifier_AttrDef_Color(); + $border_color = $this->info['border-top-color'] = $this->info['border-bottom-color'] = $this->info['border-left-color'] = @@ -60,6 +67,9 @@ class HTMLPurifier_CSSDefinition new HTMLPurifier_AttrDef_Color() )); + $this->info['border-color'] = new HTMLPurifier_AttrDef_Multiple($border_color); + + $border_width = $this->info['border-top-width'] = $this->info['border-bottom-width'] = $this->info['border-left-width'] = @@ -68,6 +78,8 @@ class HTMLPurifier_CSSDefinition new HTMLPurifier_AttrDef_CSSLength(true) //disallow negative )); + $this->info['border-width'] = new HTMLPurifier_AttrDef_Multiple($border_width); + $this->info['letter-spacing'] = new HTMLPurifier_AttrDef_Composite(array( new HTMLPurifier_AttrDef_Enum(array('normal')), new HTMLPurifier_AttrDef_CSSLength() @@ -93,6 +105,7 @@ class HTMLPurifier_CSSDefinition new HTMLPurifier_AttrDef_Percentage(true) )); + $margin = $this->info['margin-top'] = $this->info['margin-bottom'] = $this->info['margin-left'] = @@ -102,7 +115,10 @@ class HTMLPurifier_CSSDefinition new HTMLPurifier_AttrDef_Enum(array('auto')) )); + $this->info['margin'] = new HTMLPurifier_AttrDef_Multiple($margin); + // non-negative + $padding = $this->info['padding-top'] = $this->info['padding-bottom'] = $this->info['padding-left'] = @@ -111,6 +127,8 @@ class HTMLPurifier_CSSDefinition new HTMLPurifier_AttrDef_Percentage(true) )); + $this->info['padding'] = new HTMLPurifier_AttrDef_Multiple($padding); + $this->info['text-indent'] = new HTMLPurifier_AttrDef_Composite(array( new HTMLPurifier_AttrDef_CSSLength(), new HTMLPurifier_AttrDef_Percentage() diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index aff1d656..8c9204c9 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -12,6 +12,7 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness // regular cases, singular $this->assertDef('text-align:right;'); $this->assertDef('border-left-style:solid;'); + $this->assertDef('border-style:solid dotted;'); $this->assertDef('clear:right;'); $this->assertDef('float:left;'); $this->assertDef('font-style:italic;'); @@ -24,8 +25,10 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness $this->assertDef('background-color:transparent;'); $this->assertDef('color:#F00;'); $this->assertDef('border-top-color:#F00;'); + $this->assertDef('border-color:#F00 #FF0;'); $this->assertDef('border-top-width:thin;'); $this->assertDef('border-top-width:12px;'); + $this->assertDef('border-width:5px 1px 4px 2px;'); $this->assertDef('border-top-width:-12px;', false); $this->assertDef('letter-spacing:normal;'); $this->assertDef('letter-spacing:2px;'); @@ -42,8 +45,10 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness $this->assertDef('margin-left:5px;'); $this->assertDef('margin-right:20%;'); $this->assertDef('margin-top:auto;'); + $this->assertDef('margin:auto 5%;'); $this->assertDef('padding-bottom:5px;'); $this->assertDef('padding-top:20%;'); + $this->assertDef('padding:20% 10%;'); $this->assertDef('padding-top:-20%;', false); $this->assertDef('text-indent:3em;'); $this->assertDef('text-indent:5%;'); -- 2.11.4.GIT