mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-09 16:56:20 +02:00
[2.0.1] Rather than pass line number by parameter, have it be retrieved via Context. Add $ignore_error boolean to get().
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1228 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@ -31,11 +31,14 @@ class HTMLPurifier_Context
|
||||
/**
|
||||
* Retrieves a variable reference from the context.
|
||||
* @param $name String name
|
||||
* @param $ignore_error Boolean whether or not to ignore error
|
||||
*/
|
||||
function &get($name) {
|
||||
function &get($name, $ignore_error = false) {
|
||||
if (!isset($this->_storage[$name])) {
|
||||
trigger_error("Attempted to retrieve non-existent variable $name",
|
||||
E_USER_ERROR);
|
||||
if (!$ignore_error) {
|
||||
trigger_error("Attempted to retrieve non-existent variable $name",
|
||||
E_USER_ERROR);
|
||||
}
|
||||
$var = null; // so we can return by reference
|
||||
return $var;
|
||||
}
|
||||
|
@ -11,8 +11,12 @@ class HTMLPurifier_ErrorCollector
|
||||
|
||||
var $errors = array();
|
||||
var $locale;
|
||||
var $context;
|
||||
|
||||
function HTMLPurifier_ErrorCollector(&$locale) {$this->locale =& $locale;}
|
||||
function HTMLPurifier_ErrorCollector(&$context) {
|
||||
$this->locale =& $context->get('Locale');
|
||||
$this->context =& $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an error message to the collector for later use
|
||||
@ -20,20 +24,23 @@ class HTMLPurifier_ErrorCollector
|
||||
* @param $severity int Error severity, PHP error style (don't use E_USER_)
|
||||
* @param $msg string Error message text
|
||||
*/
|
||||
function send($line, $severity, $msg) {
|
||||
$token = false;
|
||||
if ($line && !is_int($line)) {
|
||||
$token = $line;
|
||||
$line = $token->line;
|
||||
if (!$line) $line = false;
|
||||
}
|
||||
if (func_num_args() == 3) $msg = $this->locale->getMessage($msg);
|
||||
else {
|
||||
$args = func_get_args();
|
||||
array_splice($args, 0, 2); // one less to make 1-based
|
||||
unset($args[0]);
|
||||
function send($severity, $msg, $args = array()) {
|
||||
if (func_num_args() == 2) {
|
||||
$msg = $this->locale->getMessage($msg);
|
||||
} else {
|
||||
// setup one-based array if necessary
|
||||
if (!is_array($args)) {
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
unset($args[0]);
|
||||
}
|
||||
$msg = $this->locale->formatMessage($msg, $args);
|
||||
}
|
||||
|
||||
$line = $this->context->get('CurrentLine', true);
|
||||
$token = $this->context->get('CurrentToken', true);
|
||||
$attr = $this->context->get('CurrentAttr', true);
|
||||
|
||||
$this->errors[] = array($line, $severity, $msg);
|
||||
}
|
||||
|
||||
|
@ -138,7 +138,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
||||
// uh oh, we have a comment that extends to
|
||||
// infinity. Can't be helped: set comment
|
||||
// end position to end of string
|
||||
if ($e) $e->send($current_line, E_WARNING, 'Lexer: Unclosed comment');
|
||||
if ($e) $e->send(E_WARNING, 'Lexer: Unclosed comment');
|
||||
$position_comment_end = strlen($html);
|
||||
$end = true;
|
||||
} else {
|
||||
@ -181,7 +181,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
||||
// have accidently grabbed an emoticon. Translate into
|
||||
// text and go our merry way
|
||||
if (!ctype_alnum($segment[0])) {
|
||||
if ($e) $e->send($current_line, E_NOTICE, 'Lexer: Unescaped lt');
|
||||
if ($e) $e->send(E_NOTICE, 'Lexer: Unescaped lt');
|
||||
$token = new
|
||||
HTMLPurifier_Token_Text(
|
||||
'<' .
|
||||
@ -261,7 +261,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
||||
continue;
|
||||
} else {
|
||||
// inside tag, but there's no ending > sign
|
||||
if ($e) $e->send($current_line, E_WARNING, 'Lexer: Missing gt');
|
||||
if ($e) $e->send(E_WARNING, 'Lexer: Missing gt');
|
||||
$token = new
|
||||
HTMLPurifier_Token_Text(
|
||||
'<' .
|
||||
@ -327,7 +327,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
||||
list($key, $quoted_value) = explode('=', $string);
|
||||
$quoted_value = trim($quoted_value);
|
||||
if (!$key) {
|
||||
if ($e) $e->send($current_line, E_ERROR, 'Lexer: Missing attribute key');
|
||||
if ($e) $e->send(E_ERROR, 'Lexer: Missing attribute key');
|
||||
return array();
|
||||
}
|
||||
if (!$quoted_value) return array($key => '');
|
||||
@ -343,7 +343,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
||||
} else {
|
||||
// not well behaved
|
||||
if ($open_quote) {
|
||||
if ($e) $e->send($current_line, E_ERROR, 'Lexer: Missing end quote');
|
||||
if ($e) $e->send(E_ERROR, 'Lexer: Missing end quote');
|
||||
$value = substr($quoted_value, 1);
|
||||
} else {
|
||||
$value = $quoted_value;
|
||||
@ -390,7 +390,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
||||
$key = substr($string, $key_begin, $key_end - $key_begin);
|
||||
|
||||
if (!$key) {
|
||||
if ($e) $e->send($current_line, E_ERROR, 'Lexer: Missing attribute key');
|
||||
if ($e) $e->send(E_ERROR, 'Lexer: Missing attribute key');
|
||||
$cursor += strcspn($string, $this->_whitespace, $cursor + 1); // prevent infinite loop
|
||||
continue; // empty key
|
||||
}
|
||||
@ -440,7 +440,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
||||
$array[$key] = $key;
|
||||
} else {
|
||||
// purely theoretical
|
||||
if ($e) $e->send($current_line, E_ERROR, 'Lexer: Missing attribute key');
|
||||
if ($e) $e->send(E_ERROR, 'Lexer: Missing attribute key');
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user