0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-03-23 14:27:02 +00:00

[1.4.0] 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.

- Also: fixed up some flaky behavior in list-style shorthand, introduced uri_or_none

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@643 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2007-01-15 01:14:24 +00:00
parent aefda60696
commit d60f345cab
4 changed files with 32 additions and 16 deletions

3
NEWS
View File

@ -11,6 +11,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
1.4.0, unknown release date 1.4.0, unknown release date
! Implemented list-style-image, URIs now allowed in list-style ! 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 . Implemented AttrDef_CSSURI for url(http://google.com) style declarations
1.3.3, unknown release date, likely to be dropped 1.3.3, unknown release date, likely to be dropped

View File

@ -37,20 +37,20 @@ class HTMLPurifier_AttrDef_ListStyle extends HTMLPurifier_AttrDef
$caught['image'] = false; $caught['image'] = false;
$i = 0; // number of catches $i = 0; // number of catches
$none = false;
foreach ($bits as $bit) { foreach ($bits as $bit) {
if ($i >= 3) return; // optimization bit if ($i >= 3) return; // optimization bit
if ($bit === '') continue; if ($bit === '') continue;
foreach ($caught as $key => $status) { foreach ($caught as $key => $status) {
if ($status !== false) continue; if ($status !== false) continue;
if ($key == 'type' && $bit == 'none') { $r = $this->info['list-style-' . $key]->validate($bit, $config, $context);
// 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);
}
if ($r === false) continue; if ($r === false) continue;
if ($r === 'none') {
if ($none) continue;
else $none = true;
if ($key == 'image') continue;
}
$caught[$key] = $r; $caught[$key] = $r;
$i++; $i++;
} }

View File

@ -52,12 +52,19 @@ class HTMLPurifier_CSSDefinition
$this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum( $this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum(
array('normal', 'small-caps'), false); 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( $this->info['list-style-position'] = new HTMLPurifier_AttrDef_Enum(
array('inside', 'outside'), false); array('inside', 'outside'), false);
$this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum( $this->info['list-style-type'] = new HTMLPurifier_AttrDef_Enum(
array('disc', 'circle', 'square', 'decimal', 'lower-roman', array('disc', 'circle', 'square', 'decimal', 'lower-roman',
'upper-roman', 'lower-alpha', 'upper-alpha'), false); 'upper-roman', 'lower-alpha', 'upper-alpha', 'none'), false);
$this->info['list-style-image'] = new HTMLPurifier_AttrDef_CSSURI(); $this->info['list-style-image'] = $uri_or_none;
$this->info['list-style'] = new HTMLPurifier_AttrDef_ListStyle($config); $this->info['list-style'] = new HTMLPurifier_AttrDef_ListStyle($config);
@ -65,13 +72,15 @@ class HTMLPurifier_CSSDefinition
array('capitalize', 'uppercase', 'lowercase', 'none'), false); array('capitalize', 'uppercase', 'lowercase', 'none'), false);
$this->info['color'] = new HTMLPurifier_AttrDef_Color(); $this->info['color'] = new HTMLPurifier_AttrDef_Color();
// technically speaking, this one should get its own validator, but $this->info['background-image'] = $uri_or_none;
// since we don't support background images, it effectively is $this->info['background-repeat'] = new HTMLPurifier_AttrDef_Enum(
// equivalent to color. The only trouble is that if the author array('repeat', 'repeat-x', 'repeat-y', 'no-repeat')
// 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 $this->info['background-attachment'] = new HTMLPurifier_AttrDef_Enum(
// info. This will be fixed in a later version (see TODO) when array('scroll', 'fixed')
// better URI filtering is implemented. );
// pending its own validator as a shorthand
$this->info['background'] = $this->info['background'] =
$border_color = $border_color =

View File

@ -74,6 +74,10 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
$this->assertDef('table-layout:fixed;'); $this->assertDef('table-layout:fixed;');
$this->assertDef('list-style-image:url(nice.jpg);'); $this->assertDef('list-style-image:url(nice.jpg);');
$this->assertDef('list-style:disc url(nice.jpg) inside;'); $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 // duplicates
$this->assertDef('text-align:right;text-align:left;', $this->assertDef('text-align:right;text-align:left;',