mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-23 00:41:52 +00:00
Implemented CSS properties whose valid values were enumerated. Accept inherit for all properties. Some composite unit tests.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@226 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
d721066d27
commit
1e2f853f4f
@ -137,31 +137,31 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
|
|||||||
<tr class="css1"><td>background</td><td>Depends on background-*</td></tr>
|
<tr class="css1"><td>background</td><td>Depends on background-*</td></tr>
|
||||||
<tr class="css1"><td>border</td><td>COMPOSITE</td></tr>
|
<tr class="css1"><td>border</td><td>COMPOSITE</td></tr>
|
||||||
<tr class="css1"><td>border-color</td><td>-</td></tr>
|
<tr class="css1"><td>border-color</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>border-style</td><td>ENUM(none, hidden, dotted, dashed,
|
<tr class="css1 impl-yes"><td>border-style</td><td>ENUM(none, hidden, dotted, dashed,
|
||||||
solid, double, groove, ridge, inset, outset)</td></tr>
|
solid, double, groove, ridge, inset, outset)</td></tr>
|
||||||
<tr class="css1"><td>border-width</td><td>-</td></tr>
|
<tr class="css1"><td>border-width</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>border-*</td><td>COMPOSITE</td></tr>
|
<tr class="css1"><td>border-*</td><td>COMPOSITE</td></tr>
|
||||||
<tr><td>border-*-color</td><td>-</td></tr>
|
<tr><td>border-*-color</td><td>-</td></tr>
|
||||||
<tr><td>border-*-style</td><td>-</td></tr>
|
<tr><td>border-*-style</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>border-*-width</td><td>-</td></tr>
|
<tr class="css1"><td>border-*-width</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>clear</td><td>ENUM(none, left, right, both)</td></tr>
|
<tr class="css1 impl-yes"><td>clear</td><td>ENUM(none, left, right, both)</td></tr>
|
||||||
<tr class="css1"><td>color</td><td>-</td></tr>
|
<tr class="css1"><td>color</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>float</td><td>ENUM(left, right, none), May require layout
|
<tr class="css1 impl-yes"><td>float</td><td>ENUM(left, right, none), May require layout
|
||||||
precautions with clear</td></tr>
|
precautions with clear</td></tr>
|
||||||
<tr class="css1"><td>font</td><td>COMPOSITE</td></tr>
|
<tr class="css1"><td>font</td><td>COMPOSITE</td></tr>
|
||||||
<tr class="css1"><td>font-family</td><td>CSS validator may complain if fallback font
|
<tr class="css1"><td>font-family</td><td>CSS validator may complain if fallback font
|
||||||
family not specified</td></tr>
|
family not specified</td></tr>
|
||||||
<tr class="css1"><td>font-size</td><td>-</td></tr>
|
<tr class="css1"><td>font-size</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>font-style</td><td>ENUM(normal, italic, oblique)</td></tr>
|
<tr class="css1 impl-yes"><td>font-style</td><td>ENUM(normal, italic, oblique)</td></tr>
|
||||||
<tr class="css1"><td>font-variant</td><td>ENUM(normal, small-caps)</td></tr>
|
<tr class="css1 impl-yes"><td>font-variant</td><td>ENUM(normal, small-caps)</td></tr>
|
||||||
<tr class="css1"><td>font-weight</td><td>ENUM(normal, bold, bolder, lighter,
|
<tr class="css1 impl-yes"><td>font-weight</td><td>ENUM(normal, bold, bolder, lighter,
|
||||||
100, 200, 300, 400, 500, 600, 700, 800, 900), maybe special code for
|
100, 200, 300, 400, 500, 600, 700, 800, 900), maybe special code for
|
||||||
in-between integers</td></tr>
|
in-between integers</td></tr>
|
||||||
<tr class="css1"><td>letter-spacing</td><td>-</td></tr>
|
<tr class="css1"><td>letter-spacing</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>line-height</td><td>-</td></tr>
|
<tr class="css1"><td>line-height</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>list-style-position</td><td>ENUM(inside, outside),
|
<tr class="css1 impl-yes"><td>list-style-position</td><td>ENUM(inside, outside),
|
||||||
Strange behavior in browsers</td></tr>
|
Strange behavior in browsers</td></tr>
|
||||||
<tr class="css1"><td>list-style-type</td><td>ENUM(...),
|
<tr class="css1 impl-yes"><td>list-style-type</td><td>ENUM(...),
|
||||||
Well-supported values are: disc, circle, square,
|
Well-supported values are: disc, circle, square,
|
||||||
decimal, lower-roman, upper-roman, lower-alpha and upper-alpha. See also
|
decimal, lower-roman, upper-roman, lower-alpha and upper-alpha. See also
|
||||||
CSS 3. Mostly IE lack of support.</td></tr>
|
CSS 3. Mostly IE lack of support.</td></tr>
|
||||||
@ -176,7 +176,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
|
|||||||
enum, can be combined (composite sorta): underline, overline,
|
enum, can be combined (composite sorta): underline, overline,
|
||||||
line-through</td></tr>
|
line-through</td></tr>
|
||||||
<tr class="css1"><td>text-indent</td><td>-</td></tr>
|
<tr class="css1"><td>text-indent</td><td>-</td></tr>
|
||||||
<tr class="css1"><td>text-transform</td><td>ENUM(capitalize, uppercase,
|
<tr class="css1 impl-yes"><td>text-transform</td><td>ENUM(capitalize, uppercase,
|
||||||
lowercase, none)</td></tr>
|
lowercase, none)</td></tr>
|
||||||
<tr class="css1"><td>width</td><td>Interesting</td></tr>
|
<tr class="css1"><td>width</td><td>Interesting</td></tr>
|
||||||
<tr class="css1"><td>word-spacing</td><td>IE 5 no support</td></tr>
|
<tr class="css1"><td>word-spacing</td><td>IE 5 no support</td></tr>
|
||||||
|
@ -21,11 +21,21 @@ class HTMLPurifier_AttrDef_CSS
|
|||||||
if (!strpos($declaration, ':')) continue;
|
if (!strpos($declaration, ':')) continue;
|
||||||
list($property, $value) = explode(':', $declaration, 2);
|
list($property, $value) = explode(':', $declaration, 2);
|
||||||
if (!isset($definition->info[$property])) continue;
|
if (!isset($definition->info[$property])) continue;
|
||||||
$result = $definition->info[$property]->validate($value,$config,$context);
|
// inefficient call, since the validator will do this again
|
||||||
|
// inherit works for everything
|
||||||
|
if (strtolower(trim($value)) !== 'inherit') {
|
||||||
|
$result = $definition->info[$property]->validate(
|
||||||
|
$value, $config, $context );
|
||||||
|
} else {
|
||||||
|
$result = 'inherit';
|
||||||
|
}
|
||||||
if ($result === false) continue;
|
if ($result === false) continue;
|
||||||
$propvalues[$property] = $result;
|
$propvalues[$property] = $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// slightly inefficient, but it's the only way of getting rid of
|
||||||
|
// duplicates. Perhaps config to optimize it, but not now.
|
||||||
|
|
||||||
$new_declarations = '';
|
$new_declarations = '';
|
||||||
foreach ($propvalues as $prop => $value) {
|
foreach ($propvalues as $prop => $value) {
|
||||||
$new_declarations .= "$prop:$value;";
|
$new_declarations .= "$prop:$value;";
|
||||||
|
@ -22,6 +22,30 @@ class HTMLPurifier_CSSDefinition
|
|||||||
|
|
||||||
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
|
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
array('left', 'right', 'center', 'justify'), false);
|
array('left', 'right', 'center', 'justify'), false);
|
||||||
|
$this->info['border-style'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
|
array('none', 'hidden', 'dotted', 'dashed', 'solid', 'double',
|
||||||
|
'groove', 'ridge', 'inset', 'outset'), false);
|
||||||
|
$this->info['clear'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
|
array('none', 'left', 'right', 'both'), false);
|
||||||
|
$this->info['float'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
|
array('none', 'left', 'right'), false);
|
||||||
|
$this->info['font-style'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
|
array('normal', 'italic', 'oblique'), false);
|
||||||
|
$this->info['font-variant'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
|
array('normal', 'small-caps'), false);
|
||||||
|
$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['text-transform'] = new HTMLPurifier_AttrDef_Enum(
|
||||||
|
array('capitalize', 'uppercase', 'lowercase', 'none'), false);
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,9 +9,36 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
|
|||||||
|
|
||||||
$this->def = new HTMLPurifier_AttrDef_CSS();
|
$this->def = new HTMLPurifier_AttrDef_CSS();
|
||||||
|
|
||||||
|
// regular cases, singular
|
||||||
$this->assertDef('text-align:right;');
|
$this->assertDef('text-align:right;');
|
||||||
|
$this->assertDef('border-style:solid;');
|
||||||
|
$this->assertDef('clear:right;');
|
||||||
|
$this->assertDef('float:left;');
|
||||||
|
$this->assertDef('font-style:italic;');
|
||||||
|
$this->assertDef('font-variant:small-caps;');
|
||||||
|
$this->assertDef('font-weight:bold;');
|
||||||
|
$this->assertDef('list-style-position:outside;');
|
||||||
|
$this->assertDef('list-style-type:upper-roman;');
|
||||||
|
$this->assertDef('text-transform:capitalize;');
|
||||||
|
|
||||||
|
// duplicates
|
||||||
$this->assertDef('text-align:right;text-align:left;', 'text-align:left;');
|
$this->assertDef('text-align:right;text-align:left;', 'text-align:left;');
|
||||||
|
|
||||||
|
// a few composites
|
||||||
|
$this->assertDef('font-variant:small-caps;font-weight:900;');
|
||||||
|
$this->assertDef('float:right;text-align:right;');
|
||||||
|
|
||||||
|
// selective removal
|
||||||
|
$this->assertDef('text-transform:capitalize;destroy:it;', 'text-transform:capitalize;');
|
||||||
|
|
||||||
|
// inherit works for everything
|
||||||
|
$this->assertDef('text-align:inherit;');
|
||||||
|
|
||||||
|
// bad props
|
||||||
|
$this->assertDef('nodice:foobar;', false);
|
||||||
|
$this->assertDef('position:absolute;', false);
|
||||||
|
$this->assertDef('background-image:url(javascript:alert\(\));', false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user