From bda2615b305b11287fe97c996e3edba6dc71cd19 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 2 Feb 2007 22:03:09 +0000 Subject: [PATCH] [1.5.0] Add support for IDREF git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@703 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + library/HTMLPurifier/AttrDef/ID.php | 22 +++++++++++++++++++--- tests/HTMLPurifier/AttrDef/IDTest.php | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 37d42853..779d9c26 100644 --- a/NEWS +++ b/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 diff --git a/library/HTMLPurifier/AttrDef/ID.php b/library/HTMLPurifier/AttrDef/ID.php index 09c277ca..63d30394 100644 --- a/library/HTMLPurifier/AttrDef/ID.php +++ b/library/HTMLPurifier/AttrDef/ID.php @@ -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 diff --git a/tests/HTMLPurifier/AttrDef/IDTest.php b/tests/HTMLPurifier/AttrDef/IDTest.php index e47ad9af..7fba690f 100644 --- a/tests/HTMLPurifier/AttrDef/IDTest.php +++ b/tests/HTMLPurifier/AttrDef/IDTest.php @@ -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('', 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 + + } + } ?> \ No newline at end of file