0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-03 05:11:52 +00:00

Commit initial implementation of AttrDef_CSS, with text-align being the only defined property. Further development will be going on in AttrDef and CSSDefinition.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@223 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-08-12 20:22:09 +00:00
parent df52406a88
commit 7c86e3cc0f
9 changed files with 91 additions and 3 deletions

View File

@ -20,6 +20,7 @@ AttrDef
out for mailto scheme, IPv6 validation is broken (fringe), unintuitive out for mailto scheme, IPv6 validation is broken (fringe), unintuitive
variable overwriting, missing validation for query, fragment and path, variable overwriting, missing validation for query, fragment and path,
no percent-encode fixing no percent-encode fixing
CSS - parser doesn't accept advanced CSS (fringe)
AttrTransform - doesn't accept AttrContext, non-validating AttrTransform - doesn't accept AttrContext, non-validating
Lang - invalid xml:lang value can overwrite valid lang value (fringe) Lang - invalid xml:lang value can overwrite valid lang value (fringe)
ChildDef - not-allowed nodes translated to text, likely invalid handling ChildDef - not-allowed nodes translated to text, likely invalid handling

View File

@ -161,7 +161,7 @@ thead th {text-align:left;padding:0.1em;background-color:#EEE;}
<tr class="css1"><td>margin-*</td><td>-</td></tr> <tr class="css1"><td>margin-*</td><td>-</td></tr>
<tr class="css1"><td>padding</td><td>-</td></tr> <tr class="css1"><td>padding</td><td>-</td></tr>
<tr class="css1"><td>padding-*</td><td>-</td></tr> <tr class="css1"><td>padding-*</td><td>-</td></tr>
<tr class="css1"><td>text-align</td><td>-</td></tr> <tr class="css1 impl-yes"><td>text-align</td><td>-</td></tr>
<tr class="css1"><td>text-decoration</td><td>No blink (argh my eyes)</td></tr> <tr class="css1"><td>text-decoration</td><td>No blink (argh my eyes)</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>-</td></tr> <tr class="css1"><td>text-transform</td><td>-</td></tr>

View File

@ -0,0 +1,35 @@
<?php
require_once 'HTMLPurifier/AttrDef.php';
require_once 'HTMLPurifier/CSSDefinition.php';
class HTMLPurifier_AttrDef_CSS
{
function validate($css, $config, &$context) {
$definition = HTMLPurifier_CSSDefinition::instance();
// we're going to break the spec and explode by semicolons.
// This is because semicolon rarely appears in escaped form
$declarations = explode(';', $css);
$new_declarations = '';
foreach ($declarations as $declaration) {
if (!$declaration) continue;
if (!strpos($declaration, ':')) continue;
list($property, $value) = explode(':', $declaration, 2);
if (!isset($definition->info[$property])) continue;
$result = $definition->info[$property]->validate($value,$config,$context);
if ($result === false) continue;
$new_declarations .= "$property:$result;";
}
return $new_declarations ? $new_declarations : false;
}
}
?>

View File

@ -0,0 +1,30 @@
<?php
class HTMLPurifier_CSSDefinition
{
var $info = array();
function &instance($prototype = null) {
static $instance = null;
if ($prototype) {
$instance = $prototype;
} elseif (!$instance) {
$instance = new HTMLPurifier_CSSDefinition();
$instance->setup();
}
return $instance;
}
function HTMLPurifier_CSSDefinition() {}
function setup() {
$this->info['text-align'] = new HTMLPurifier_AttrDef_Enum(
array('left', 'right', 'center', 'justify'), false);
}
}
?>

View File

@ -255,6 +255,7 @@ class HTMLPurifier_Definition
'id' => new HTMLPurifier_AttrDef_ID(), 'id' => new HTMLPurifier_AttrDef_ID(),
'class' => new HTMLPurifier_AttrDef_Class(), 'class' => new HTMLPurifier_AttrDef_Class(),
'title' => $e_Text, 'title' => $e_Text,
'style' => new HTMLPurifier_AttrDef_CSS(),
// i18n // i18n
'dir' => new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false), 'dir' => new HTMLPurifier_AttrDef_Enum(array('ltr','rtl'), false),
'lang' => new HTMLPurifier_AttrDef_Lang(), 'lang' => new HTMLPurifier_AttrDef_Lang(),

View File

@ -1,5 +1,7 @@
<?php <?php
// pretty-printing with indentation would be pretty cool
class HTMLPurifier_Generator class HTMLPurifier_Generator
{ {

View File

@ -0,0 +1,18 @@
<?php
require_once 'HTMLPurifier/AttrDef/CSS.php';
class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_CSS();
$this->assertDef('text-align:right;');
}
}
?>

View File

@ -64,8 +64,8 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends
$expect[11] = '<span lang="fr" xml:lang="fr">La soupe.</span>'; $expect[11] = '<span lang="fr" xml:lang="fr">La soupe.</span>';
// test align (won't work till CSS validation is implemented) // test align (won't work till CSS validation is implemented)
// $inputs[12] = '<h1 align="center">Centered Headline</h1>'; $inputs[12] = '<h1 align="center">Centered Headline</h1>';
// $expect[12] = '<h1 style="text-align:center;">Centered Headline</h1>'; $expect[12] = '<h1 style="text-align:center;">Centered Headline</h1>';
// test table // test table
$inputs[13] = <<<HTML $inputs[13] = <<<HTML

View File

@ -63,6 +63,7 @@ $test_files[] = 'AttrDef/PixelsTest.php';
$test_files[] = 'AttrDef/LengthTest.php'; $test_files[] = 'AttrDef/LengthTest.php';
$test_files[] = 'AttrDef/NumberSpanTest.php'; $test_files[] = 'AttrDef/NumberSpanTest.php';
$test_files[] = 'AttrDef/URITest.php'; $test_files[] = 'AttrDef/URITest.php';
$test_files[] = 'AttrDef/CSSTest.php';
$test_files[] = 'IDAccumulatorTest.php'; $test_files[] = 'IDAccumulatorTest.php';
$test_files[] = 'TagTransformTest.php'; $test_files[] = 'TagTransformTest.php';
$test_files[] = 'AttrTransform/LangTest.php'; $test_files[] = 'AttrTransform/LangTest.php';