0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 23:28:42 +00:00

Commit Multiple AttrDef, forms scaffolding for a few more CSS properties.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@272 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2006-08-16 00:34:37 +00:00
parent 1388beb456
commit 2d28380763
3 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
require_once 'HTMLPurifier/AttrDef.php';
class HTMLPurifier_AttrDef_Multiple extends HTMLPurifier_AttrDef
{
var $single;
var $max;
function HTMLPurifier_AttrDef_Multiple($single, $max = 4) {
$this->single = $single;
$this->max = $max;
}
function validate($string, $config, &$context) {
$string = $this->parseCDATA($string);
if ($string === '') return false;
$parts = explode(' ', $string); // parseCDATA replaced \r, \t and \n
$length = count($parts);
$final = '';
for ($i = 0, $num = 0; $i < $length && $num < $this->max; $i++) {
if (ctype_space($parts[$i])) continue;
$result = $this->single->validate($parts[$i], $config, $context);
if ($result !== false) {
$final .= $result . ' ';
$num++;
}
}
if ($final === '') return false;
return rtrim($final);
}
}
?>

View File

@ -0,0 +1,30 @@
<?php
require_once 'HTMLPurifier/AttrDef/Integer.php';
require_once 'HTMLPurifier/AttrDef/Multiple.php';
class HTMLPurifier_AttrDef_MultipleTest extends HTMLPurifier_AttrDefHarness
{
function test() {
$this->def = new HTMLPurifier_AttrDef_Multiple(
new HTMLPurifier_AttrDef_Integer()
);
$this->assertDef('1 2 3 4');
$this->assertDef('6');
$this->assertDef('4 5');
$this->assertDef(' 2 54 2 3', '2 54 2 3');
$this->assertDef("6\r3", '6 3');
$this->assertDef('asdf', false);
$this->assertDef('a s d f', false);
$this->assertDef('1 2 3 4 5', '1 2 3 4');
$this->assertDef('1 2 invalid 3', '1 2 3');
}
}
?>

View File

@ -70,6 +70,7 @@ $test_files[] = 'AttrDef/IntegerTest.php';
$test_files[] = 'AttrDef/NumberTest.php';
$test_files[] = 'AttrDef/CSSLengthTest.php';
$test_files[] = 'AttrDef/PercentageTest.php';
$test_files[] = 'AttrDef/MultipleTest.php';
$test_files[] = 'IDAccumulatorTest.php';
$test_files[] = 'TagTransformTest.php';
$test_files[] = 'AttrTransform/LangTest.php';