diff --git a/library/HTMLPurifier/AttrDef/Multiple.php b/library/HTMLPurifier/AttrDef/Multiple.php new file mode 100644 index 00000000..4ffb1a66 --- /dev/null +++ b/library/HTMLPurifier/AttrDef/Multiple.php @@ -0,0 +1,36 @@ +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); + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/AttrDef/MultipleTest.php b/tests/HTMLPurifier/AttrDef/MultipleTest.php new file mode 100644 index 00000000..e5e6b986 --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/MultipleTest.php @@ -0,0 +1,30 @@ +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'); + + + } + +} + +?> \ No newline at end of file diff --git a/tests/index.php b/tests/index.php index 8aab3589..fda09381 100644 --- a/tests/index.php +++ b/tests/index.php @@ -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';