mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-05 05:37:49 +02:00
Migrate AttrValidator to nested error format; modify generator logic in ErrorCollector.
AttrValidator's changes are fairly self-explanatory, but ErrorCollector's changes are worth a little discussion. ErrorCollector can use generators at various points during its flow control; there are two distinct generators that it should use: 1. The one used for the output, and 2. The one used for the error output. These will usually be the same, but in the odd case where they need to be different, getHTMLFormatted() will accept an alterate configuration object with an appropriate doctype. Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
@@ -49,15 +49,23 @@ class HTMLPurifier_AttrValidator
|
||||
// do global transformations (pre)
|
||||
// nothing currently utilizes this
|
||||
foreach ($definition->info_attr_transform_pre as $transform) {
|
||||
if ($e) $e->start();
|
||||
$attr = $transform->transform($o = $attr, $config, $context);
|
||||
if ($e && ($attr != $o)) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
|
||||
if ($e) {
|
||||
if ($attr != $o) $e->end(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
|
||||
else $e->end();
|
||||
}
|
||||
}
|
||||
|
||||
// do local transformations only applicable to this element (pre)
|
||||
// ex. <p align="right"> to <p style="text-align:right;">
|
||||
foreach ($definition->info[$token->name]->attr_transform_pre as $transform) {
|
||||
if ($e) $e->start();
|
||||
$attr = $transform->transform($o = $attr, $config, $context);
|
||||
if ($e && ($attr != $o)) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
|
||||
if ($e) {
|
||||
if ($attr != $o) $e->end(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
|
||||
else $e->end();
|
||||
}
|
||||
}
|
||||
|
||||
// create alias to this element's attribute definition array, see
|
||||
@@ -72,6 +80,7 @@ class HTMLPurifier_AttrValidator
|
||||
// Watch out for name collisions: $key has previously been used
|
||||
foreach ($attr as $attr_key => $value) {
|
||||
|
||||
if ($e) $e->start();
|
||||
// call the definition
|
||||
if ( isset($defs[$attr_key]) ) {
|
||||
// there is a local definition defined
|
||||
@@ -103,7 +112,7 @@ class HTMLPurifier_AttrValidator
|
||||
if ($result === false || $result === null) {
|
||||
// this is a generic error message that should replaced
|
||||
// with more specific ones when possible
|
||||
if ($e) $e->send(E_ERROR, 'AttrValidator: Attribute removed');
|
||||
if ($e) $e->end(E_ERROR, 'AttrValidator: Attribute removed');
|
||||
|
||||
// remove the attribute
|
||||
unset($attr[$attr_key]);
|
||||
@@ -114,6 +123,9 @@ class HTMLPurifier_AttrValidator
|
||||
|
||||
// simple substitution
|
||||
$attr[$attr_key] = $result;
|
||||
if ($e) $e->end();
|
||||
} else {
|
||||
if ($e) $e->end();
|
||||
}
|
||||
|
||||
// we'd also want slightly more complicated substitution
|
||||
@@ -129,14 +141,22 @@ class HTMLPurifier_AttrValidator
|
||||
|
||||
// global (error reporting untested)
|
||||
foreach ($definition->info_attr_transform_post as $transform) {
|
||||
if ($e) $e->start();
|
||||
$attr = $transform->transform($o = $attr, $config, $context);
|
||||
if ($e && ($attr != $o)) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
|
||||
if ($e) {
|
||||
if ($attr != $o) $e->end(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
|
||||
else $e->end();
|
||||
}
|
||||
}
|
||||
|
||||
// local (error reporting untested)
|
||||
foreach ($definition->info[$token->name]->attr_transform_post as $transform) {
|
||||
if ($e) $e->start();
|
||||
$attr = $transform->transform($o = $attr, $config, $context);
|
||||
if ($e && ($attr != $o)) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
|
||||
if ($e) {
|
||||
if ($attr != $o) $e->end(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
|
||||
else $e->end();
|
||||
}
|
||||
}
|
||||
|
||||
$token->attr = $attr;
|
||||
|
@@ -25,10 +25,9 @@ class HTMLPurifier_ErrorCollector
|
||||
|
||||
public function __construct($context) {
|
||||
$this->locale =& $context->get('Locale');
|
||||
$this->generator =& $context->get('Generator');
|
||||
$this->context = $context;
|
||||
$this->_current =& $this->_stacks[0];
|
||||
$this->errors =& $this->_stacks[0];
|
||||
$this->errors =& $this->_stacks[0];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,6 +140,7 @@ class HTMLPurifier_ErrorCollector
|
||||
public function getHTMLFormatted($config, $errors = null) {
|
||||
$ret = array();
|
||||
|
||||
$generator = new HTMLPurifier_Generator($config, $this->context);
|
||||
if ($errors === null) $errors = $this->errors;
|
||||
|
||||
// sort error array by line
|
||||
@@ -161,7 +161,7 @@ class HTMLPurifier_ErrorCollector
|
||||
list($line, $severity, $msg, $children) = $error;
|
||||
$string = '';
|
||||
$string .= '<strong>' . $this->locale->getErrorName($severity) . '</strong>: ';
|
||||
$string .= $this->generator->escape($msg);
|
||||
$string .= $generator->escape($msg);
|
||||
if ($line) {
|
||||
// have javascript link generation that causes
|
||||
// textarea to skip to the specified line
|
||||
|
Reference in New Issue
Block a user