From 806901cfd297e9a210460436a7c82909f85ab717 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 3 Feb 2007 20:15:33 +0000 Subject: [PATCH] [1.5.0] Rename Class to Nmtokens (more accurate) git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@706 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 1 + .../AttrDef/{Class.php => Nmtokens.php} | 14 +++++++++----- library/HTMLPurifier/HTMLDefinition.php | 4 ++-- .../AttrDef/{ClassTest.php => NmtokensTest.php} | 6 +++--- tests/test_files.php | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) rename library/HTMLPurifier/AttrDef/{Class.php => Nmtokens.php} (69%) rename tests/HTMLPurifier/AttrDef/{ClassTest.php => NmtokensTest.php} (80%) diff --git a/NEWS b/NEWS index 779d9c26..63ee7bf8 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ! Added a rudimentary I18N and L10N system modeled off MediaWiki - Allow 'x' subtag in language codes . Added support for IDREF attributes (i.e. for) +. Renamed HTMLPurifier_AttrDef_Class to HTMLPurifier_AttrDef_Nmtokens 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/Class.php b/library/HTMLPurifier/AttrDef/Nmtokens.php similarity index 69% rename from library/HTMLPurifier/AttrDef/Class.php rename to library/HTMLPurifier/AttrDef/Nmtokens.php index 5f86823a..d0749ceb 100644 --- a/library/HTMLPurifier/AttrDef/Class.php +++ b/library/HTMLPurifier/AttrDef/Nmtokens.php @@ -4,9 +4,13 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/Config.php'; /** - * Validates the contents of the global HTML attribute class. + * Validates contents based on NMTOKENS attribute type. + * @note The only current use for this is the class attribute in HTML + * @note Could have some functionality factored out into Nmtoken class + * @warning We cannot assume this class will be used only for 'class' + * attributes. Not sure how to hook in magic behavior, then. */ -class HTMLPurifier_AttrDef_Class extends HTMLPurifier_AttrDef +class HTMLPurifier_AttrDef_Nmtokens extends HTMLPurifier_AttrDef { function validate($string, $config, &$context) { @@ -31,10 +35,10 @@ class HTMLPurifier_AttrDef_Class extends HTMLPurifier_AttrDef if (empty($matches[1])) return false; - // reconstruct class string + // reconstruct string $new_string = ''; - foreach ($matches[1] as $class_names) { - $new_string .= $class_names . ' '; + foreach ($matches[1] as $token) { + $new_string .= $token . ' '; } $new_string = rtrim($new_string); diff --git a/library/HTMLPurifier/HTMLDefinition.php b/library/HTMLPurifier/HTMLDefinition.php index 79fc3fab..d1823af6 100644 --- a/library/HTMLPurifier/HTMLDefinition.php +++ b/library/HTMLPurifier/HTMLDefinition.php @@ -3,7 +3,7 @@ require_once 'HTMLPurifier/AttrDef.php'; require_once 'HTMLPurifier/AttrDef/Enum.php'; require_once 'HTMLPurifier/AttrDef/ID.php'; - require_once 'HTMLPurifier/AttrDef/Class.php'; + require_once 'HTMLPurifier/AttrDef/Nmtokens.php'; require_once 'HTMLPurifier/AttrDef/Text.php'; require_once 'HTMLPurifier/AttrDef/Lang.php'; require_once 'HTMLPurifier/AttrDef/Pixels.php'; @@ -398,7 +398,7 @@ class HTMLPurifier_HTMLDefinition // which manually override these in their local definitions $this->info_global_attr = array( // core attrs - 'class' => new HTMLPurifier_AttrDef_Class(), + 'class' => new HTMLPurifier_AttrDef_Nmtokens(), 'title' => $e_Text, 'style' => new HTMLPurifier_AttrDef_CSS(), // i18n diff --git a/tests/HTMLPurifier/AttrDef/ClassTest.php b/tests/HTMLPurifier/AttrDef/NmtokensTest.php similarity index 80% rename from tests/HTMLPurifier/AttrDef/ClassTest.php rename to tests/HTMLPurifier/AttrDef/NmtokensTest.php index 053e5134..8b38a491 100644 --- a/tests/HTMLPurifier/AttrDef/ClassTest.php +++ b/tests/HTMLPurifier/AttrDef/NmtokensTest.php @@ -1,15 +1,15 @@ def = new HTMLPurifier_AttrDef_Class(); + $this->def = new HTMLPurifier_AttrDef_Nmtokens(); $this->assertDef('valid'); $this->assertDef('a0-_'); diff --git a/tests/test_files.php b/tests/test_files.php index 541b1c44..499022fa 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -25,7 +25,7 @@ $test_files[] = 'Strategy/ValidateAttributesTest.php'; $test_files[] = 'AttrDefTest.php'; $test_files[] = 'AttrDef/EnumTest.php'; $test_files[] = 'AttrDef/IDTest.php'; -$test_files[] = 'AttrDef/ClassTest.php'; +$test_files[] = 'AttrDef/NmtokensTest.php'; $test_files[] = 'AttrDef/TextTest.php'; $test_files[] = 'AttrDef/LangTest.php'; $test_files[] = 'AttrDef/PixelsTest.php';