From fd384129bf67e4b53b41183948661913ae1655a7 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 27 Jun 2008 15:44:27 -0400 Subject: [PATCH] Proper support for name attribute in and Prior to this commit, the name attribute was unilaterally removed, except for Strict doctypes or a heavy TidyLevel, when it was converted to an id attribute. As name is actually permitted in both HTML 4.01 Strict and XHTML 1.0 Strict, although deprecated, the more sensible default behavior is to allow it unless TidyLevel is heavy. Our implementation is slightly stricter than the specs, as name attributes are treated as first class IDs, disallowing or duplicate names. The former should be treated as a special case, but that will be a separate commit. Signed-off-by: Edward Z. Yang --- NEWS | 3 ++ TODO | 2 +- configdoc/usage.xml | 29 ++++++++++--------- library/HTMLPurifier.includes.php | 2 ++ library/HTMLPurifier.safe-includes.php | 2 ++ library/HTMLPurifier/HTMLModule/Name.php | 16 ++++++++++ library/HTMLPurifier/HTMLModule/Tidy/Name.php | 23 +++++++++++++++ .../HTMLModule/Tidy/XHTMLAndHTML4.php | 4 --- library/HTMLPurifier/HTMLModuleManager.php | 17 +++++++---- tests/HTMLPurifierTest.php | 6 ++++ 10 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 library/HTMLPurifier/HTMLModule/Name.php create mode 100644 library/HTMLPurifier/HTMLModule/Tidy/Name.php diff --git a/NEWS b/NEWS index 40c9dd9a..683ed7b3 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ! %Output.AttrSort for when you need your attributes in alphabetical order to deal with a bug in FCKEditor. Requested by frank farmer. ! Enable HTML comments when %HTML.Trusted is on. Requested by Waldo Jaquith. +! Proper support for name attribute. It is now allowed and equivalent to the id + attribute in a and img tags, and is only converted to id when %HTML.TidyLevel + is heavy (for all doctypes). . Strategy_MakeWellFormed now operates in-place, saving memory and allowing for more interesting filter-backtracking diff --git a/TODO b/TODO index c83ae974..64a5e96d 100644 --- a/TODO +++ b/TODO @@ -14,7 +14,7 @@ afraid to cast your vote for the next feature to be implemented! - Investigate how early internal structures can be accessed; this would prevent structures from being parsed and serialized multiple times. - Built-in support for target="_blank" on all external links -- Gitify the repository +- Allow - 44 + 47 @@ -151,7 +151,7 @@ - 198 + 199 238 @@ -162,30 +162,33 @@ 34 - - - - 205 + + 23 - + 206 + + + 207 + + - 220 + 221 - 225 + 226 - 228 + 229 @@ -366,7 +369,7 @@ - 22 + 21 19 @@ -374,12 +377,12 @@ - 22 + 25 - 23 + 26 diff --git a/library/HTMLPurifier.includes.php b/library/HTMLPurifier.includes.php index 620957a9..35c70049 100644 --- a/library/HTMLPurifier.includes.php +++ b/library/HTMLPurifier.includes.php @@ -141,6 +141,7 @@ require 'HTMLPurifier/HTMLModule/Hypertext.php'; require 'HTMLPurifier/HTMLModule/Image.php'; require 'HTMLPurifier/HTMLModule/Legacy.php'; require 'HTMLPurifier/HTMLModule/List.php'; +require 'HTMLPurifier/HTMLModule/Name.php'; require 'HTMLPurifier/HTMLModule/NonXMLCommonAttributes.php'; require 'HTMLPurifier/HTMLModule/Object.php'; require 'HTMLPurifier/HTMLModule/Presentation.php'; @@ -155,6 +156,7 @@ require 'HTMLPurifier/HTMLModule/Target.php'; require 'HTMLPurifier/HTMLModule/Text.php'; require 'HTMLPurifier/HTMLModule/Tidy.php'; require 'HTMLPurifier/HTMLModule/XMLCommonAttributes.php'; +require 'HTMLPurifier/HTMLModule/Tidy/Name.php'; require 'HTMLPurifier/HTMLModule/Tidy/Proprietary.php'; require 'HTMLPurifier/HTMLModule/Tidy/XHTMLAndHTML4.php'; require 'HTMLPurifier/HTMLModule/Tidy/Strict.php'; diff --git a/library/HTMLPurifier.safe-includes.php b/library/HTMLPurifier.safe-includes.php index 97db35ca..631dcce3 100644 --- a/library/HTMLPurifier.safe-includes.php +++ b/library/HTMLPurifier.safe-includes.php @@ -135,6 +135,7 @@ require_once $__dir . '/HTMLPurifier/HTMLModule/Hypertext.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Image.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Legacy.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/List.php'; +require_once $__dir . '/HTMLPurifier/HTMLModule/Name.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/NonXMLCommonAttributes.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Object.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Presentation.php'; @@ -149,6 +150,7 @@ require_once $__dir . '/HTMLPurifier/HTMLModule/Target.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Text.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/XMLCommonAttributes.php'; +require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/Name.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/Proprietary.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/XHTMLAndHTML4.php'; require_once $__dir . '/HTMLPurifier/HTMLModule/Tidy/Strict.php'; diff --git a/library/HTMLPurifier/HTMLModule/Name.php b/library/HTMLPurifier/HTMLModule/Name.php new file mode 100644 index 00000000..db2ab4f4 --- /dev/null +++ b/library/HTMLPurifier/HTMLModule/Name.php @@ -0,0 +1,16 @@ +addBlankElement($name); + $element->attr['name'] = 'ID'; + } + } + +} diff --git a/library/HTMLPurifier/HTMLModule/Tidy/Name.php b/library/HTMLPurifier/HTMLModule/Tidy/Name.php new file mode 100644 index 00000000..9056e5fe --- /dev/null +++ b/library/HTMLPurifier/HTMLModule/Tidy/Name.php @@ -0,0 +1,23 @@ +doctypes->register( 'HTML 4.01 Strict', false, array_merge($common, $non_xml), - array('Tidy_Strict', 'Tidy_Proprietary'), + array('Tidy_Strict', 'Tidy_Proprietary', 'Tidy_Name'), array(), '-//W3C//DTD HTML 4.01//EN', 'http://www.w3.org/TR/html4/strict.dtd' @@ -91,7 +92,7 @@ class HTMLPurifier_HTMLModuleManager $this->doctypes->register( 'XHTML 1.0 Transitional', true, array_merge($common, $transitional, $xml, $non_xml), - array('Tidy_Transitional', 'Tidy_XHTML', 'Tidy_Proprietary'), + array('Tidy_Transitional', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_Name'), array(), '-//W3C//DTD XHTML 1.0 Transitional//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd' @@ -100,7 +101,7 @@ class HTMLPurifier_HTMLModuleManager $this->doctypes->register( 'XHTML 1.0 Strict', true, array_merge($common, $xml, $non_xml), - array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Strict', 'Tidy_Proprietary'), + array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Strict', 'Tidy_Proprietary', 'Tidy_Name'), array(), '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd' @@ -109,7 +110,7 @@ class HTMLPurifier_HTMLModuleManager $this->doctypes->register( 'XHTML 1.1', true, array_merge($common, $xml, array('Ruby')), - array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_Strict'), // Tidy_XHTML1_1 + array('Tidy_Strict', 'Tidy_XHTML', 'Tidy_Proprietary', 'Tidy_Strict', 'Tidy_Name'), // Tidy_XHTML1_1 array(), '-//W3C//DTD XHTML 1.1//EN', 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd' @@ -378,7 +379,11 @@ class HTMLPurifier_HTMLModuleManager $this->contentSets->generateChildDef($def, $module); } - + + // This can occur if there is a blank definition, but no base to + // mix it in with + if (!$def) return false; + // add information on required attributes foreach ($def->attr as $attr_name => $attr_def) { if ($attr_def->required) { diff --git a/tests/HTMLPurifierTest.php b/tests/HTMLPurifierTest.php index 4f6c19a3..b1ef5e94 100644 --- a/tests/HTMLPurifierTest.php +++ b/tests/HTMLPurifierTest.php @@ -226,5 +226,11 @@ alert(""); ); } + function test_name() { + $this->config->set('Attr', 'EnableID', true); + $this->config->set('HTML', 'Doctype', 'XHTML 1.0 Strict'); + $this->assertPurification(''); + } + }