0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-01-03 05:11:52 +00:00

Undo start()/end() error collector changes in AttrValidator.

Signed-off-by: Edward Z. Yang <edwardzyang@thewritingpot.com>
This commit is contained in:
Edward Z. Yang 2008-09-05 17:25:35 -04:00
parent ed7983b559
commit 3184fee468
3 changed files with 8 additions and 93 deletions

View File

@ -49,22 +49,18 @@ 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) {
if ($attr != $o) $e->end(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
else $e->end();
if ($attr != $o) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
}
}
// 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) {
if ($attr != $o) $e->end(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
else $e->end();
if ($attr != $o) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
}
}
@ -80,7 +76,6 @@ 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
@ -112,7 +107,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->end(E_ERROR, 'AttrValidator: Attribute removed');
if ($e) $e->send(E_ERROR, 'AttrValidator: Attribute removed');
// remove the attribute
unset($attr[$attr_key]);
@ -123,9 +118,8 @@ class HTMLPurifier_AttrValidator
// simple substitution
$attr[$attr_key] = $result;
if ($e) $e->end();
} else {
if ($e) $e->end();
// nothing happens
}
// we'd also want slightly more complicated substitution
@ -141,21 +135,17 @@ 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) {
if ($attr != $o) $e->end(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
else $e->end();
if ($attr != $o) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
}
}
// 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) {
if ($attr != $o) $e->end(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
else $e->end();
if ($attr != $o) $e->send(E_NOTICE, 'AttrValidator: Attributes transformed', $o, $attr);
}
}

View File

@ -77,51 +77,6 @@ class HTMLPurifier_ErrorCollector
);
}
/**
* Begins the collection of a number of sub-errors. This is useful if you
* are entering a function that may generate errors, but you are able
* to detect the overall state afterwards.
*/
public function start() {
$this->_stacks[] = array();
$this->_resetCurrent();
}
/**
* Terminates the collection of sub-errors, interface is otherwise identical
* to send(). Any sub-errors will be registered as children (3) to this
* error.
*
* @param $severity int Error severity
* @param $msg string Error message text
* @param $subst1 string First substitution for $msg
* @param $subst2 string ...
*
* @note If end() is called with no parameters, it is quiet unless there
* were sub-errors.
*/
public function end() {
$stack = array_pop($this->_stacks);
$this->_resetCurrent();
$args = func_get_args();
if ($args) {
call_user_func_array(array($this, 'send'), $args);
} elseif ($stack) {
$this->send(E_NOTICE, 'ErrorCollector: Incidental errors');
}
if ($stack) {
$this->_current[count($this->_current) - 1][3] = $stack;
}
}
/**
* Resets the _current member variable to the top of the stacks; i.e.
* the active set of errors being collected.
*/
protected function _resetCurrent() {
$this->_current =& $this->_stacks[count($this->_stacks) - 1];
}
/**
* Retrieves raw error data for custom formatter to use
* @param List of arrays in format of array(line of error,

View File

@ -112,6 +112,7 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
}
/*
function testNestedErrors() {
$this->language->setReturnValue('getMessage', 'Message 1', array('message-1'));
$this->language->setReturnValue('getMessage', 'Message 2', array('message-2'));
@ -142,38 +143,7 @@ class HTMLPurifier_ErrorCollectorTest extends HTMLPurifier_Harness
$this->assertIdentical($formatted_result, $formatted_expect);
}
function testNestedErrorsQuiet() {
$this->language->setReturnValue('getMessage', 'Incidental errors', array('ErrorCollector: Incidental errors'));
$this->language->setReturnValue('getMessage', 'Message', array('message'));
$this->language->setReturnValue('formatMessage', ' at line 4', array('ErrorCollector: At line', array('line' => 4)));
$this->line = 4;
$this->collector->start();
$this->collector->send(E_WARNING, 'message');
$this->collector->end();
$expect = array(
0 => array(4, E_NOTICE, 'Incidental errors', array(
0 => array(4, E_WARNING, 'Message', array()),
)),
);
$result = $this->collector->getRaw();
$this->assertIdentical($result, $expect);
}
function testNestedErrorsReallyQuiet() {
$this->collector->start();
$this->collector->end();
$expect = array();
$result = $this->collector->getRaw();
$this->assertIdentical($result, $expect);
}
*/
}