diff --git a/NEWS b/NEWS index c7360e20..d3e6ef8b 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ! With %Core.AggressivelyFixLt, <3 and similar emoticons no longer trigger HTML removal in PHP5 (DOMLex). This directive is not necessary for PHP4 (DirectLex). +- AutoFormatters emit friendly error messages if tags or attributes they + need are not allowed 2.0.2, unknown release date (none) diff --git a/library/HTMLPurifier/Injector.php b/library/HTMLPurifier/Injector.php index 93dbf735..580366e6 100644 --- a/library/HTMLPurifier/Injector.php +++ b/library/HTMLPurifier/Injector.php @@ -8,6 +8,11 @@ class HTMLPurifier_Injector { + /** + * Advisory name of injector, this is for friendly error messages + */ + var $name; + /** * Amount of tokens the injector needs to skip + 1. Because * the decrement is the first thing that happens, this needs to @@ -40,16 +45,37 @@ class HTMLPurifier_Injector var $inputIndex; /** - * Prepares the injector by giving it the config and context objects, - * so that important variables can be extracted and not passed via - * parameter constantly. Remember: always instantiate a new injector - * when handling a set of HTML. + * Array of elements and attributes this injector creates and therefore + * need to be allowed by the definition. Takes form of + * array('element' => array('attr', 'attr2'), 'element2') + */ + var $needed = array(); + + /** + * Prepares the injector by giving it the config and context objects: + * this allows references to important variables to be made within + * the injector. This function also checks if the HTML environment + * will work with the Injector: if p tags are not allowed, the + * Auto-Paragraphing injector should not be enabled. + * @param $config Instance of HTMLPurifier_Config + * @param $context Instance of HTMLPurifier_Context + * @return Boolean false if success, string of missing needed element/attribute if failure */ function prepare($config, &$context) { $this->htmlDefinition = $config->getHTMLDefinition(); + // perform $needed checks + foreach ($this->needed as $element => $attributes) { + if (is_int($element)) $element = $attributes; + if (!isset($this->htmlDefinition->info[$element])) return $element; + if (!is_array($attributes)) continue; + foreach ($attributes as $name) { + if (!isset($this->htmlDefinition->info[$element]->attr[$name])) return "$element.$name"; + } + } $this->currentNesting =& $context->get('CurrentNesting'); $this->inputTokens =& $context->get('InputTokens'); $this->inputIndex =& $context->get('InputIndex'); + return false; } /** diff --git a/library/HTMLPurifier/Injector/AutoParagraph.php b/library/HTMLPurifier/Injector/AutoParagraph.php index 920cce92..82bbc725 100644 --- a/library/HTMLPurifier/Injector/AutoParagraph.php +++ b/library/HTMLPurifier/Injector/AutoParagraph.php @@ -15,6 +15,11 @@ HTMLPurifier_ConfigSchema::define( block elements in nodes that allow paragraph tags
+ p
tags must be allowed for this directive to take effect.
+ We do not use br
tags for paragraphing, as that is
+ semantically incorrect.
+
This directive has been available since 2.0.1.
@@ -27,6 +32,9 @@ HTMLPurifier_ConfigSchema::define( class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector { + var $name = 'AutoParagraph'; + var $needed = array('p'); + function _pStart() { $par = new HTMLPurifier_Token_Start('p'); $par->armor['MakeWellFormed_TagClosedError'] = true; diff --git a/library/HTMLPurifier/Injector/Linkify.php b/library/HTMLPurifier/Injector/Linkify.php index 4269e7a4..bf7abfa9 100644 --- a/library/HTMLPurifier/Injector/Linkify.php +++ b/library/HTMLPurifier/Injector/Linkify.php @@ -6,7 +6,8 @@ HTMLPurifier_ConfigSchema::define( 'AutoFormat', 'Linkify', false, 'bool', '
This directive turns on linkification, auto-linking http, ftp and
- https URLs. This directive has been available since 2.0.1.
+ https URLs. a
tags with the href
attribute
+ must be allowed. This directive has been available since 2.0.1.
Internal auto-formatter that converts configuration directives in
- syntax %Namespace.Directive to links. This directive has been available
- since 2.0.1.
+ syntax %Namespace.Directive to links. a
tags
+ with the href
attribute must be allowed.
+ This directive has been available since 2.0.1.