0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

[3.1.1] More ConfigSchema optimizations: degenerate form can accommodate type and allow_null

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1766 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang 2008-05-23 17:10:26 +00:00
parent 895141e0b5
commit 917d2ea5ef
4 changed files with 48 additions and 20 deletions

View File

@ -208,15 +208,23 @@ class HTMLPurifier_Config
trigger_error("$namespace.$key is an alias, preferred directive name is $new_ns.$new_dir", E_USER_NOTICE);
return;
}
// Raw type might be negative when using the fully optimized form
// of stdclass, which indicates allow_null == true
$rtype =
is_int($this->def->info[$namespace][$key]) ?
$this->def->info[$namespace][$key] :
$this->def->info[$namespace][$key]->type;
if ($rtype < 0) {
$type = -$rtype;
$allow_null = true;
} else {
$type = $rtype;
$allow_null = isset($this->def->info[$namespace][$key]->allow_null);
}
try {
$value = $this->parser->parse(
$value,
$type =
is_int($this->def->info[$namespace][$key]) ?
$this->def->info[$namespace][$key] :
$this->def->info[$namespace][$key]->type,
isset($this->def->info[$namespace][$key]->allow_null)
);
$value = $this->parser->parse($value, $type, $allow_null);
} catch (HTMLPurifier_VarParserException $e) {
trigger_error('Value for ' . "$namespace.$key" . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING);
return;

View File

@ -31,6 +31,11 @@ class HTMLPurifier_ConfigSchema {
* - namespace: Namespace this directive aliases to
* - name: Directive name this directive aliases to
*
* In certain degenerate cases, stdclass will actually be an integer. In
* that case, the value is equivalent to an stdclass with the type
* property set to the integer. If the integer is negative, type is
* equal to the absolute value of integer, and allow_null is true.
*
* This class is friendly with HTMLPurifier_Config. If you need introspection
* about the schema, you're better of using the ConfigSchema_Interchange,
* which uses more memory but has much richer information.
@ -137,6 +142,21 @@ class HTMLPurifier_ConfigSchema {
$this->info[$namespace][$name] = $obj;
}
/**
* Replaces any stdclass that only has the type property with type integer.
*/
public function postProcess() {
foreach ($this->info as $namespace => $info) {
foreach ($info as $directive => $v) {
if (count((array) $v) == 1) {
$this->info[$namespace][$directive] = $v->type;
} elseif (count((array) $v) == 2 && isset($v->allow_null)) {
$this->info[$namespace][$directive] = -$v->type;
}
}
}
}
// DEPRECATED METHODS
/** @see HTMLPurifier_ConfigSchema->set() */

File diff suppressed because one or more lines are too long

View File

@ -7,17 +7,17 @@
class HTMLPurifier_VarParser
{
const STRING = 0;
const ISTRING = 1;
const TEXT = 2;
const ITEXT = 3;
const INT = 4;
const FLOAT = 5;
const BOOL = 6;
const LOOKUP = 7;
const ALIST = 8;
const HASH = 9;
const MIXED = 10;
const STRING = 1;
const ISTRING = 2;
const TEXT = 3;
const ITEXT = 4;
const INT = 5;
const FLOAT = 6;
const BOOL = 7;
const LOOKUP = 8;
const ALIST = 9;
const HASH = 10;
const MIXED = 11;
/**
* Lookup table of allowed types. Mainly for backwards compatibility, but