diff --git a/NEWS b/NEWS index c6e16ebf..35ace744 100644 --- a/NEWS +++ b/NEWS @@ -32,6 +32,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier of the operational document type . Lexer is now pre-emptively included, with a conditional include for the PHP5 only version. +. HTMLDefinition and CSSDefinition have a common parent class: Definition. 1.6.1, released 2007-05-05 ! Support for more deprecated attributes via transformations: diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index 23a66ab7..4db04694 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -1,5 +1,7 @@ info['text-align'] = new HTMLPurifier_AttrDef_Enum( array('left', 'right', 'center', 'justify'), false); diff --git a/library/HTMLPurifier/Config.php b/library/HTMLPurifier/Config.php index 10db8245..38011a53 100644 --- a/library/HTMLPurifier/Config.php +++ b/library/HTMLPurifier/Config.php @@ -200,11 +200,11 @@ class HTMLPurifier_Config $this->html_definition = HTMLPurifier_HTMLDefinition::getCache($this); if ($this->html_definition) return $this->html_definition; } - $this->html_definition = new HTMLPurifier_HTMLDefinition($this); + $this->html_definition = new HTMLPurifier_HTMLDefinition(); if ($raw) return $this->html_definition; // no setup! } if (!$this->html_definition->setup) { - $this->html_definition->setup(); + $this->html_definition->setup($this); $this->html_definition->saveCache($this); } return $this->html_definition; diff --git a/library/HTMLPurifier/HTMLDefinition.php b/library/HTMLPurifier/HTMLDefinition.php index d75be453..5b66a871 100644 --- a/library/HTMLPurifier/HTMLDefinition.php +++ b/library/HTMLPurifier/HTMLDefinition.php @@ -1,6 +1,6 @@ config = $config; + function HTMLPurifier_HTMLDefinition() { $this->manager = new HTMLPurifier_HTMLModuleManager(); } @@ -207,31 +202,18 @@ class HTMLPurifier_HTMLDefinition fclose($fh); } - /** - * Processes internals into form usable by HTMLPurifier internals. - * Modifying the definition after calling this function should not - * be done. - */ - function setup() { - - // multiple call guard - if ($this->setup) {return;} else {$this->setup = true;} - - $this->processModules(); - $this->setupConfigStuff(); - - // remove complicated variables to ease serialization - unset($this->config); + function doSetup($config) { + $this->processModules($config); + $this->setupConfigStuff($config); unset($this->manager); - } /** * Extract out the information from the manager */ - function processModules() { + function processModules($config) { - $this->manager->setup($this->config); + $this->manager->setup($config); $this->doctype = $this->manager->doctype; foreach ($this->manager->modules as $module) { @@ -257,9 +239,9 @@ class HTMLPurifier_HTMLDefinition /** * Sets up stuff based on config. We need a better way of doing this. */ - function setupConfigStuff() { + function setupConfigStuff($config) { - $block_wrapper = $this->config->get('HTML', 'BlockWrapper'); + $block_wrapper = $config->get('HTML', 'BlockWrapper'); if (isset($this->info_content_sets['Block'][$block_wrapper])) { $this->info_block_wrapper = $block_wrapper; } else { @@ -267,7 +249,7 @@ class HTMLPurifier_HTMLDefinition E_USER_ERROR); } - $parent = $this->config->get('HTML', 'Parent'); + $parent = $config->get('HTML', 'Parent'); $def = $this->manager->getElement($parent, true); if ($def) { $this->info_parent = $parent; @@ -283,7 +265,7 @@ class HTMLPurifier_HTMLDefinition "support forums) "; // setup allowed elements, SubtractiveWhitelist module(?) - $allowed_elements = $this->config->get('HTML', 'AllowedElements'); + $allowed_elements = $config->get('HTML', 'AllowedElements'); if (is_array($allowed_elements)) { foreach ($this->info as $name => $d) { if(!isset($allowed_elements[$name])) unset($this->info[$name]); @@ -296,7 +278,7 @@ class HTMLPurifier_HTMLDefinition } } - $allowed_attributes = $this->config->get('HTML', 'AllowedAttributes'); + $allowed_attributes = $config->get('HTML', 'AllowedAttributes'); $allowed_attributes_mutable = $allowed_attributes; // by copy! if (is_array($allowed_attributes)) { foreach ($this->info_global_attr as $attr_key => $info) { diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php index 61381731..5952d2f4 100644 --- a/tests/HTMLPurifier/ConfigTest.php +++ b/tests/HTMLPurifier/ConfigTest.php @@ -228,19 +228,23 @@ class HTMLPurifier_ConfigTest extends UnitTestCase $this->old_copy = HTMLPurifier_ConfigSchema::instance($this->old_copy); $config = HTMLPurifier_Config::createDefault(); + $config->set('HTML', 'Doctype', 'XHTML 1.0 Strict'); $config->autoFinalize = false; $def = $config->getCSSDefinition(); $this->assertIsA($def, 'HTMLPurifier_CSSDefinition'); - $def = $config->getHTMLDefinition(); - $def2 = $config->getHTMLDefinition(); + $def =& $config->getHTMLDefinition(); + $def2 =& $config->getHTMLDefinition(); $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition'); - $this->assertIdentical($def, $def2); + $this->assertReference($def, $def2); $this->assertTrue($def->setup); // test re-calculation if HTML changes - $config->set('HTML', 'Strict', true); + unset($def, $def2); + $def2 = $config->getHTMLDefinition(); // forcibly de-reference + + $config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); $def = $config->getHTMLDefinition(); $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition'); $this->assertNotEqual($def, $def2);