From c0b38bab8500333c13685ec6ced0c1abc23b8d35 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Sat, 21 Apr 2007 02:31:38 +0000 Subject: [PATCH] [1.6.1] Invert HTMLModuleManager->addModule() processing order to check prefixes first and then the literal module git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@971 48356398-32a2-884e-a903-53898d9a118a --- NEWS | 2 ++ library/HTMLPurifier/HTMLModuleManager.php | 29 ++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 7ebee219..83eef453 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier a non-alphanumeric character. This means that certain emoticons are now preserved. - Possibly fatal bug with __autoload() fixed in module manager +- Invert HTMLModuleManager->addModule() processing order to check + prefixes first and then the literal module 1.6.0, released 2007-04-01 ! Support for most common deprecated attributes via transformations: diff --git a/library/HTMLPurifier/HTMLModuleManager.php b/library/HTMLPurifier/HTMLModuleManager.php index 250ddd12..ff630c7a 100644 --- a/library/HTMLPurifier/HTMLModuleManager.php +++ b/library/HTMLPurifier/HTMLModuleManager.php @@ -208,20 +208,33 @@ class HTMLPurifier_HTMLModuleManager * subclass of HTMLPurifier_HTMLModule. * @note This function will not call autoload, you must instantiate * (and thus invoke) autoload outside the method. + * @note If a string is passed as a module name, different variants + * will be tested in this order: + * - Check for HTMLPurifier_HTMLModule_$name + * - Check all prefixes with $name in order they were added + * - Check for literal object name + * - Throw fatal error + * If your object name collides with an internal class, specify + * your module manually. */ function addModule($module) { if (is_string($module)) { $original_module = $module; - if (!class_exists($module, false)) { - foreach ($this->prefixes as $prefix) { - $module = $prefix . $original_module; - if (class_exists($module)) break; + $ok = false; + foreach ($this->prefixes as $prefix) { + $module = $prefix . $original_module; + if (class_exists($module)) { + $ok = true; + break; } } - if (!class_exists($module, false)) { - trigger_error($original_module . ' module does not exist', - E_USER_ERROR); - return; + if (!$ok) { + $module = $original_module; + if (!class_exists($module, false)) { + trigger_error($original_module . ' module does not exist', + E_USER_ERROR); + return; + } } $module = new $module(); }