From a520b5469ec07f5b5d0e3a71490f37e845f90d29 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sun, 6 Aug 2006 01:03:48 +0000 Subject: [PATCH] Implement Pixels attribute definition. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@169 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier/AttrDef/Pixels.php | 30 ++++++++++++++ library/HTMLPurifier/Config.php | 4 ++ library/HTMLPurifier/Definition.php | 3 ++ tests/HTMLPurifier/AttrDef/PixelsTest.php | 39 +++++++++++++++++++ .../Strategy/ValidateAttributesTest.php | 2 +- tests/index.php | 2 + 6 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 library/HTMLPurifier/AttrDef/Pixels.php create mode 100644 tests/HTMLPurifier/AttrDef/PixelsTest.php diff --git a/library/HTMLPurifier/AttrDef/Pixels.php b/library/HTMLPurifier/AttrDef/Pixels.php new file mode 100644 index 00000000..4c04a855 --- /dev/null +++ b/library/HTMLPurifier/AttrDef/Pixels.php @@ -0,0 +1,30 @@ + \ No newline at end of file diff --git a/library/HTMLPurifier/Config.php b/library/HTMLPurifier/Config.php index 5ead680b..a94b2b56 100644 --- a/library/HTMLPurifier/Config.php +++ b/library/HTMLPurifier/Config.php @@ -35,6 +35,10 @@ class HTMLPurifier_Config // at all. var $attr_lang_alpha = false; + // max amount of pixels allowed to be specified + var $attr_pixels_hmax = 600; // horizontal context + var $attr_pixels_vmax = 1200; // vertical context + function createDefault() { $config = new HTMLPurifier_Config(); return $config; diff --git a/library/HTMLPurifier/Definition.php b/library/HTMLPurifier/Definition.php index 964bc672..0fe46332 100644 --- a/library/HTMLPurifier/Definition.php +++ b/library/HTMLPurifier/Definition.php @@ -6,6 +6,7 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/AttrDef/Class.php'; require_once 'HTMLPurifier/AttrDef/Text.php'; require_once 'HTMLPurifier/AttrDef/Lang.php'; + require_once 'HTMLPurifier/AttrDef/Pixels.php'; require_once 'HTMLPurifier/AttrTransform.php'; require_once 'HTMLPurifier/AttrTransform/Lang.php'; require_once 'HTMLPurifier/AttrTransform/TextAlign.php'; @@ -296,6 +297,8 @@ class HTMLPurifier_Definition $this->info['table']->attr['rules'] = $e_TRules; $this->info['table']->attr['summary'] = $e_Text; + $this->info['table']->attr['border'] = new HTMLPurifier_AttrDef_Pixels(); + ////////////////////////////////////////////////////////////////////// // UNIMP : info_tag_transform : transformations of tags diff --git a/tests/HTMLPurifier/AttrDef/PixelsTest.php b/tests/HTMLPurifier/AttrDef/PixelsTest.php new file mode 100644 index 00000000..ad62235b --- /dev/null +++ b/tests/HTMLPurifier/AttrDef/PixelsTest.php @@ -0,0 +1,39 @@ +def = new HTMLPurifier_AttrDef_Pixels(); + + $this->assertDef('1'); + $this->assertDef('0'); + + $this->assertDef('2px', '2'); // rm px suffix + + $this->assertDef('dfs', false); // totally invalid value + + // conceivably we could repair this value, but we won't for now + $this->assertDef('9in', false); + + // test trim + $this->assertDef(' 45 ', '45'); + + // no negatives + $this->assertDef('-2', '0'); + + // remove empty + $this->assertDef('', false); + + // round down + $this->assertDef('4.9', '4'); + + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php index 6adbb66e..17d6ba08 100644 --- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php +++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php @@ -69,7 +69,7 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends // test table $inputs[13] = << + diff --git a/tests/index.php b/tests/index.php index 6b5580cb..a7ee1e2b 100644 --- a/tests/index.php +++ b/tests/index.php @@ -43,11 +43,13 @@ $test_files[] = 'AttrDef/IDTest.php'; $test_files[] = 'AttrDef/ClassTest.php'; $test_files[] = 'AttrDef/TextTest.php'; $test_files[] = 'AttrDef/LangTest.php'; +$test_files[] = 'AttrDef/PixelsTest.php'; $test_files[] = 'IDAccumulatorTest.php'; $test_files[] = 'TagTransformTest.php'; $test_files[] = 'AttrTransform/LangTest.php'; $test_files[] = 'AttrTransform/TextAlignTest.php'; + $test_file_lookup = array_flip($test_files); if (isset($_GET['file']) && isset($test_file_lookup[$_GET['file']])) {
Supercalifragilistic