From 2d2838076359a54711c3df982204033ae347c698 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Wed, 16 Aug 2006 00:34:37 +0000 Subject: [PATCH] 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 --- library/HTMLPurifier/AttrDef/Multiple.php | 36 +++++++++++++++++++++ tests/HTMLPurifier/AttrDef/MultipleTest.php | 30 +++++++++++++++++ tests/index.php | 1 + 3 files changed, 67 insertions(+) create mode 100644 library/HTMLPurifier/AttrDef/Multiple.php create mode 100644 tests/HTMLPurifier/AttrDef/MultipleTest.php 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';