mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 15:28:40 +00: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:
parent
e1a5d10e75
commit
bda2615b30
1
NEWS
1
NEWS
@ -12,6 +12,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
||||
1.5.0, unknown release date
|
||||
! Added a rudimentary I18N and L10N system modeled off MediaWiki
|
||||
- Allow 'x' subtag in language codes
|
||||
. Added support for IDREF attributes (i.e. for)
|
||||
|
||||
1.4.2, unknown release date
|
||||
! docs/enduser-utf8.html explains how to use UTF-8 and HTML Purifier
|
||||
|
@ -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
|
||||
|
@ -74,6 +74,25 @@ class HTMLPurifier_AttrDef_IDTest extends HTMLPurifier_AttrDefHarness
|
||||
|
||||
}
|
||||
|
||||
function testIDReference() {
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_ID(true);
|
||||
|
||||
$this->assertDef('good_id');
|
||||
$this->assertDef('good_id'); // duplicates okay
|
||||
$this->assertDef('<b>', false);
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_ID();
|
||||
|
||||
$this->assertDef('good_id');
|
||||
$this->assertDef('good_id', false); // duplicate now not okay
|
||||
|
||||
$this->def = new HTMLPurifier_AttrDef_ID(true);
|
||||
|
||||
$this->assertDef('good_id'); // reference still okay
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user