From 1102dc6e27a3696c105167226cc777dd6521dfaf Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 29 Mar 2007 23:19:53 +0000 Subject: [PATCH] [1.6.0] Add support for name transformation to id git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@921 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + docs/dev-progress.html | 4 +-- library/HTMLPurifier/AttrTransform/Name.php | 31 +++++++++++++++++++ .../HTMLModule/TransformToStrict.php | 6 +++- tests/HTMLPurifier/AttrTransform/NameTest.php | 28 +++++++++++++++++ .../Strategy/ValidateAttributesTest.php | 7 +++++ tests/test_files.php | 1 + 7 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 library/HTMLPurifier/AttrTransform/Name.php create mode 100644 tests/HTMLPurifier/AttrTransform/NameTest.php diff --git a/NEWS b/NEWS index 7365809a..9098e537 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ! Support for all deprecated attributes via attribute transformations + bgcolor in td, th, tr and table + border in img + + name in a and img + (incomplete) 1.5.1, unknown release date diff --git a/docs/dev-progress.html b/docs/dev-progress.html index 796d9343..9587739b 100644 --- a/docs/dev-progress.html +++ b/docs/dev-progress.html @@ -279,8 +279,8 @@ Mozilla on inside and needs -moz-outline, no IE support. heightTD, THNear-equiv style 'height', needs px suffix if original was in pixels hspaceIMGNear-equiv styles 'margin-top' and 'margin-bottom', needs px suffix lang*Copy value to xml:lang -nameIMGTurn into ID - ATurn into ID? (not deprecated, though in which specs?) +nameIMGTurn into ID + ATurn into ID noshadeHRBoolean, style 'border-style:solid;' nowrapTD, THBoolean, style 'white-space:nowrap;' (not compat with IE5) sizeHRNear-equiv 'width', needs px suffix if original was pixels diff --git a/library/HTMLPurifier/AttrTransform/Name.php b/library/HTMLPurifier/AttrTransform/Name.php new file mode 100644 index 00000000..0f815b69 --- /dev/null +++ b/library/HTMLPurifier/AttrTransform/Name.php @@ -0,0 +1,31 @@ + \ No newline at end of file diff --git a/library/HTMLPurifier/HTMLModule/TransformToStrict.php b/library/HTMLPurifier/HTMLModule/TransformToStrict.php index 0660d68e..08a64fa1 100644 --- a/library/HTMLPurifier/HTMLModule/TransformToStrict.php +++ b/library/HTMLPurifier/HTMLModule/TransformToStrict.php @@ -10,6 +10,7 @@ require_once 'HTMLPurifier/AttrTransform/Lang.php'; require_once 'HTMLPurifier/AttrTransform/TextAlign.php'; require_once 'HTMLPurifier/AttrTransform/BgColor.php'; require_once 'HTMLPurifier/AttrTransform/Border.php'; +require_once 'HTMLPurifier/AttrTransform/Name.php'; /** * Proprietary module that transforms deprecated elements into Strict @@ -23,7 +24,7 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule // we're actually modifying these elements, not defining them var $elements = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', - 'blockquote', 'table', 'td', 'th', 'tr', 'img'); + 'blockquote', 'table', 'td', 'th', 'tr', 'img', 'a'); var $info_tag_transform = array( // placeholders, see constructor for definitions @@ -83,6 +84,9 @@ class HTMLPurifier_HTMLModule_TransformToStrict extends HTMLPurifier_HTMLModule $this->info['img']->attr_transform_pre['border'] = new HTMLPurifier_AttrTransform_Border(); + $this->info['img']->attr_transform_pre['name'] = + $this->info['a']->attr_transform_pre['name'] = new HTMLPurifier_AttrTransform_Name(); + } var $defines_child_def = true; diff --git a/tests/HTMLPurifier/AttrTransform/NameTest.php b/tests/HTMLPurifier/AttrTransform/NameTest.php new file mode 100644 index 00000000..da4498fb --- /dev/null +++ b/tests/HTMLPurifier/AttrTransform/NameTest.php @@ -0,0 +1,28 @@ +obj = new HTMLPurifier_AttrTransform_Name(); + } + + function test() { + $this->assertResult( array() ); + $this->assertResult( + array('name' => 'free'), + array('id' => 'free') + ); + $this->assertResult( + array('name' => 'tryit', 'id' => 'tobad'), + array('id' => 'tobad') + ); + } + +} + +?> \ No newline at end of file diff --git a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php index 048369dd..2ece54d4 100644 --- a/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php +++ b/tests/HTMLPurifier/Strategy/ValidateAttributesTest.php @@ -172,6 +172,13 @@ class HTMLPurifier_Strategy_ValidateAttributesTest extends 'Invalid image' ); + // name rewritten as id + $this->assertResult( + '', + '', + array('HTML.EnableAttrID' => true) + ); + } } diff --git a/tests/test_files.php b/tests/test_files.php index 9806d011..9f357bbb 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -38,6 +38,7 @@ $test_files[] = 'AttrTransform/BgColorTest.php'; $test_files[] = 'AttrTransform/BorderTest.php'; $test_files[] = 'AttrTransform/ImgRequiredTest.php'; $test_files[] = 'AttrTransform/LangTest.php'; +$test_files[] = 'AttrTransform/NameTest.php'; $test_files[] = 'AttrTransform/TextAlignTest.php'; $test_files[] = 'ChildDef/ChameleonTest.php'; $test_files[] = 'ChildDef/CustomTest.php';