1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-04 21:28:06 +02:00

[1.5.0] Add support for IDREF

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@703 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-02-02 22:03:09 +00:00
parent e1a5d10e75
commit bda2615b30
3 changed files with 39 additions and 3 deletions

View File

@@ -39,6 +39,20 @@ HTMLPurifier_ConfigSchema::define(
class HTMLPurifier_AttrDef_ID extends HTMLPurifier_AttrDef
{
/**
* Is the ID an actual ID, or a reference to one?
* @note IDAccumulator checking is disabled for references
* @bool
*/
var $ref = false;
/**
* @param $ref bool indication if it's ID or IDREF
*/
function HTMLPurifier_AttrDef_ID($ref = false) {
$this->ref = $ref;
}
function validate($id, $config, &$context) {
$id = trim($id); // trim it first
@@ -55,8 +69,10 @@ class HTMLPurifier_AttrDef_ID extends HTMLPurifier_AttrDef
'%Attr.IDPrefix is set', E_USER_WARNING);
}
$id_accumulator =& $context->get('IDAccumulator');
if (isset($id_accumulator->ids[$id])) return false;
if (!$this->ref) {
$id_accumulator =& $context->get('IDAccumulator');
if (isset($id_accumulator->ids[$id])) return false;
}
// we purposely avoid using regex, hopefully this is faster
@@ -71,7 +87,7 @@ class HTMLPurifier_AttrDef_ID extends HTMLPurifier_AttrDef
$result = ($trim === '');
}
if ($result) $id_accumulator->add($id);
if (!$this->ref && $result) $id_accumulator->add($id);
// if no change was made to the ID, return the result
// else, return the new id if stripping whitespace made it