diff --git a/NEWS b/NEWS index 2356f0fa..b8ae6e24 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier 1.4.0, unknown release date ! Implemented list-style-image, URIs now allowed in list-style +! Implemented background-image, background-repeat and background-attachment + CSS properties. background shorthand property HAS NOT been extended + to allow these, and background-position IS NOT implemented yet. . Implemented AttrDef_CSSURI for url(http://google.com) style declarations 1.3.3, unknown release date, likely to be dropped diff --git a/library/HTMLPurifier/AttrDef/ListStyle.php b/library/HTMLPurifier/AttrDef/ListStyle.php index 488637b4..b866798c 100644 --- a/library/HTMLPurifier/AttrDef/ListStyle.php +++ b/library/HTMLPurifier/AttrDef/ListStyle.php @@ -37,20 +37,20 @@ class HTMLPurifier_AttrDef_ListStyle extends HTMLPurifier_AttrDef $caught['image'] = false; $i = 0; // number of catches + $none = false; foreach ($bits as $bit) { if ($i >= 3) return; // optimization bit if ($bit === '') continue; foreach ($caught as $key => $status) { if ($status !== false) continue; - if ($key == 'type' && $bit == 'none') { - // there's no none for image, since you simply - // omit it if you don't want to use it. - $r = 'none'; - } else { - $r = $this->info['list-style-' . $key]->validate($bit, $config, $context); - } + $r = $this->info['list-style-' . $key]->validate($bit, $config, $context); if ($r === false) continue; + if ($r === 'none') { + if ($none) continue; + else $none = true; + if ($key == 'image') continue; + } $caught[$key] = $r; $i++; } diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index ac646939..d2227e03 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -52,12 +52,19 @@ class HTMLPurifier_CSSDefinition $this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum( array('normal', 'small-caps'), false); + $uri_or_none = new HTMLPurifier_AttrDef_Composite( + array( + new HTMLPurifier_AttrDef_Enum(array('none')), + new HTMLPurifier_AttrDef_CSSURI() + ) + ); + $this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum( array('inside', 'outside'), false); $this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum( array('disc', 'circle', 'square', 'decimal', 'lower-roman', - 'upper-roman', 'lower-alpha', 'upper-alpha'), false); - $this->info['list-style-image'] = new HTMLPurifier_AttrDef_CSSURI(); + 'upper-roman', 'lower-alpha', 'upper-alpha', 'none'), false); + $this->info['list-style-image'] = $uri_or_none; $this->info['list-style'] = new HTMLPurifier_AttrDef_ListStyle($config); @@ -65,13 +72,15 @@ class HTMLPurifier_CSSDefinition array('capitalize', 'uppercase', 'lowercase', 'none'), false); $this->info['color'] = new HTMLPurifier_AttrDef_Color(); - // technically speaking, this one should get its own validator, but - // since we don't support background images, it effectively is - // equivalent to color. The only trouble is that if the author - // specifies an image and a color, they'll both end up getting dropped, - // even though we ought to implement it and just discard the image - // info. This will be fixed in a later version (see TODO) when - // better URI filtering is implemented. + $this->info['background-image'] = $uri_or_none; + $this->info['background-repeat'] = new HTMLPurifier_AttrDef_Enum( + array('repeat', 'repeat-x', 'repeat-y', 'no-repeat') + ); + $this->info['background-attachment'] = new HTMLPurifier_AttrDef_Enum( + array('scroll', 'fixed') + ); + + // pending its own validator as a shorthand $this->info['background'] = $border_color = diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index 96789ebb..cb5e8083 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -74,6 +74,10 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness $this->assertDef('table-layout:fixed;'); $this->assertDef('list-style-image:url(nice.jpg);'); $this->assertDef('list-style:disc url(nice.jpg) inside;'); + $this->assertDef('background-image:url(foo.jpg);'); + $this->assertDef('background-image:none;'); + $this->assertDef('background-repeat:repeat-y;'); + $this->assertDef('background-attachment:fixed;'); // duplicates $this->assertDef('text-align:right;text-align:left;',