From a16d6c434258e9b2801276f92db9d2d2e4f489da Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 29 Mar 2007 21:20:44 +0000 Subject: [PATCH] [1.6.0] Add support for bgcolor attribute transform. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@919 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 5 +++ docs/dev-progress.html | 6 +-- .../HTMLPurifier/AttrTransform/BgColor.php | 28 ++++++++++++ .../HTMLPurifier/AttrTransform/TextAlign.php | 2 +- .../HTMLModule/TransformToStrict.php | 9 +++- .../AttrTransform/BgColorTest.php | 43 +++++++++++++++++++ tests/test_files.php | 1 + 7 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 library/HTMLPurifier/AttrTransform/BgColor.php create mode 100644 tests/HTMLPurifier/AttrTransform/BgColorTest.php diff --git a/NEWS b/NEWS index ea7738b7..f52f3525 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,11 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier . Internal change ========================== +1.6.0, unknown release date +! Support for all deprecated attributes via attribute transformations + + bgcolor in td, th, tr and table + + (incomplete) + 1.5.1, unknown release date - Fix segfault in unit test. The problem is not very reproduceable and I don't know what causes it, but a six line patch fixed it. diff --git a/docs/dev-progress.html b/docs/dev-progress.html index be35a9b6..3e53633c 100644 --- a/docs/dev-progress.html +++ b/docs/dev-progress.html @@ -269,9 +269,9 @@ Mozilla on inside and needs -moz-outline, no IE support. HRNear-equivalent style 'text-align' (Works for IE and Opera, but not Firefox). Also try margin-right:auto; margin-left:0; for left or margin-right:0; margin-left:auto; for right (optionally replacing 0 with the original margin for that side) H1, H2, H3, H4, H5, H6, PEquivalent style 'text-align' altIMGRequired, insert image filename if src is present or default invalid image text -bgcolorTABLEEquivalent style 'background-color' - TREquivalent style 'background-color' - TD, THEquivalent style 'background-color' +bgcolorTABLESuperset style 'background-color' + TRSuperset style 'background-color' + TD, THSuperset style 'background-color' borderIMGNear equivalent style 'border-width', as it only applies when link present clearBRNear-equiv style 'clear', transform 'all' into 'both' compactDL, OL, ULBoolean, needs custom CSS class; rarely used anyway diff --git a/library/HTMLPurifier/AttrTransform/BgColor.php b/library/HTMLPurifier/AttrTransform/BgColor.php new file mode 100644 index 00000000..abfd0342 --- /dev/null +++ b/library/HTMLPurifier/AttrTransform/BgColor.php @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/library/HTMLPurifier/AttrTransform/TextAlign.php b/library/HTMLPurifier/AttrTransform/TextAlign.php index 84e5a016..09088fe1 100644 --- a/library/HTMLPurifier/AttrTransform/TextAlign.php +++ b/library/HTMLPurifier/AttrTransform/TextAlign.php @@ -6,7 +6,7 @@ require_once 'HTMLPurifier/AttrTransform.php'; * Pre-transform that changes deprecated align attribute to text-align. */ class HTMLPurifier_AttrTransform_TextAlign - extends HTMLPurifier_AttrTransform { +extends HTMLPurifier_AttrTransform { function transform($attr, $config, &$context) { diff --git a/library/HTMLPurifier/HTMLModule/TransformToStrict.php b/library/HTMLPurifier/HTMLModule/TransformToStrict.php index d228f84f..275f551d 100644 --- a/library/HTMLPurifier/HTMLModule/TransformToStrict.php +++ b/library/HTMLPurifier/HTMLModule/TransformToStrict.php @@ -8,6 +8,7 @@ require_once 'HTMLPurifier/TagTransform/Font.php'; require_once 'HTMLPurifier/AttrTransform/Lang.php'; require_once 'HTMLPurifier/AttrTransform/TextAlign.php'; +require_once 'HTMLPurifier/AttrTransform/BgColor.php'; /** * Proprietary module that transforms deprecated elements into Strict @@ -20,7 +21,8 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule var $name = 'TransformToStrict'; // we're actually modifying these elements, not defining them - var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote'); + var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', + 'blockquote', 'table', 'td', 'th', 'tr'); var $info_tag_transform = array( // placeholders, see constructor for definitions @@ -73,6 +75,11 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule $this->info['blockquote']->content_model_type = 'strictblockquote'; $this->info['blockquote']->child = false; // recalculate please! + $this->info['table']->attr_transform_pre['bgcolor'] = + $this->info['tr']->attr_transform_pre['bgcolor'] = + $this->info['td']->attr_transform_pre['bgcolor'] = + $this->info['th']->attr_transform_pre['bgcolor'] = new HTMLPurifier_AttrTransform_BgColor(); + } var $defines_child_def = true; diff --git a/tests/HTMLPurifier/AttrTransform/BgColorTest.php b/tests/HTMLPurifier/AttrTransform/BgColorTest.php new file mode 100644 index 00000000..6ad35bde --- /dev/null +++ b/tests/HTMLPurifier/AttrTransform/BgColorTest.php @@ -0,0 +1,43 @@ +obj = new HTMLPurifier_AttrTransform_BgColor(); + } + + function test() { + + $this->assertResult( array() ); + + // we currently rely on the CSS validator to fix any problems. + // This means that this transform, strictly speaking, supports + // a superset of the functionality. + + $this->assertResult( + array('bgcolor' => '#000000'), + array('style' => 'background-color:#000000;') + ); + + $this->assertResult( + array('bgcolor' => '#000000', 'style' => 'font-weight:bold'), + array('style' => 'background-color:#000000;font-weight:bold') + ); + + // this may change when we natively support the datatype and + // validate its contents before forwarding it on + $this->assertResult( + array('bgcolor' => '#F00'), + array('style' => 'background-color:#F00;') + ); + + } + +} + +?> \ No newline at end of file diff --git a/tests/test_files.php b/tests/test_files.php index 9a612181..f77b80b4 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -34,6 +34,7 @@ $test_files[] = 'AttrDef/URI/IPv6Test.php'; $test_files[] = 'AttrDef/URITest.php'; $test_files[] = 'AttrDefTest.php'; $test_files[] = 'AttrTransform/BdoDirTest.php'; +$test_files[] = 'AttrTransform/BgColorTest.php'; $test_files[] = 'AttrTransform/ImgRequiredTest.php'; $test_files[] = 'AttrTransform/LangTest.php'; $test_files[] = 'AttrTransform/TextAlignTest.php';