From 86ca784da32a3f0359c87e115d5081d36c56ae9b Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 19 Feb 2009 19:17:49 -0500 Subject: [PATCH] Convert all to new configuration get/set format. Signed-off-by: Edward Z. Yang --- configdoc/usage.xml | 402 +----------------- docs/dev-config-bcbreaks.txt | 2 +- docs/examples/basic.php | 4 +- library/HTMLPurifier.kses.php | 6 +- library/HTMLPurifier.php | 2 +- library/HTMLPurifier/AttrDef/CSS/Color.php | 2 +- library/HTMLPurifier/AttrDef/HTML/Color.php | 2 +- .../HTMLPurifier/AttrDef/HTML/FrameTarget.php | 2 +- library/HTMLPurifier/AttrDef/HTML/ID.php | 10 +- .../HTMLPurifier/AttrDef/HTML/LinkTypes.php | 2 +- library/HTMLPurifier/AttrDef/URI.php | 2 +- library/HTMLPurifier/AttrTransform/BdoDir.php | 2 +- .../AttrTransform/ImgRequired.php | 8 +- library/HTMLPurifier/CSSDefinition.php | 10 +- library/HTMLPurifier/ChildDef/Required.php | 2 +- library/HTMLPurifier/Config.php | 80 +++- library/HTMLPurifier/DefinitionCache.php | 4 +- .../DefinitionCache/Serializer.php | 2 +- .../HTMLPurifier/DefinitionCacheFactory.php | 2 +- library/HTMLPurifier/DoctypeRegistry.php | 8 +- library/HTMLPurifier/Encoder.php | 10 +- .../Filter/ExtractStyleBlocks.php | 6 +- library/HTMLPurifier/Generator.php | 8 +- library/HTMLPurifier/HTMLDefinition.php | 14 +- library/HTMLPurifier/HTMLModule/Image.php | 4 +- library/HTMLPurifier/HTMLModule/SafeEmbed.php | 2 +- .../HTMLPurifier/HTMLModule/SafeObject.php | 2 +- library/HTMLPurifier/HTMLModule/Tidy.php | 6 +- library/HTMLPurifier/HTMLModuleManager.php | 12 +- library/HTMLPurifier/IDAccumulator.php | 2 +- .../HTMLPurifier/Injector/PurifierLinkify.php | 2 +- library/HTMLPurifier/LanguageFactory.php | 2 +- library/HTMLPurifier/Lexer.php | 10 +- library/HTMLPurifier/Lexer/DOMLex.php | 2 +- library/HTMLPurifier/Lexer/DirectLex.php | 12 +- library/HTMLPurifier/Printer/ConfigForm.php | 2 +- .../HTMLPurifier/Strategy/MakeWellFormed.php | 2 +- .../Strategy/RemoveForeignElements.php | 12 +- library/HTMLPurifier/URIDefinition.php | 8 +- .../HTMLPurifier/URIFilter/HostBlacklist.php | 2 +- library/HTMLPurifier/URIFilter/Munge.php | 6 +- library/HTMLPurifier/URISchemeRegistry.php | 4 +- maintenance/update-config.php | 34 ++ plugins/phorum/htmlpurifier.php | 2 +- smoketests/attrTransform.php | 2 +- smoketests/basic.php | 4 +- smoketests/xssAttacks.php | 2 +- tests/HTMLPurifier/AttrDef/CSSTest.php | 6 +- .../AttrDef/HTML/FrameTargetTest.php | 2 +- tests/HTMLPurifier/AttrDef/HTML/IDTest.php | 14 +- .../AttrDef/HTML/LinkTypesTest.php | 2 +- tests/HTMLPurifier/AttrDef/URITest.php | 8 +- .../HTMLPurifier/AttrTransform/BdoDirTest.php | 2 +- .../AttrTransform/ImgRequiredTest.php | 14 +- .../HTMLPurifier/AttrValidator_ErrorsTest.php | 4 +- tests/HTMLPurifier/ChildDef/RequiredTest.php | 2 +- .../ChildDef/StrictBlockquoteTest.php | 6 +- tests/HTMLPurifier/ChildDef/TableTest.php | 4 +- tests/HTMLPurifier/ConfigTest.php | 147 ++++--- .../DefinitionCache/SerializerTest.php | 14 +- .../DefinitionCacheFactoryTest.php | 6 +- tests/HTMLPurifier/DefinitionCacheTest.php | 2 +- tests/HTMLPurifier/EncoderTest.php | 26 +- .../Filter/ExtractStyleBlocksTest.php | 20 +- tests/HTMLPurifier/GeneratorTest.php | 14 +- tests/HTMLPurifier/HTMLDefinitionTest.php | 58 +-- tests/HTMLPurifier/HTMLModule/FormsTest.php | 6 +- tests/HTMLPurifier/HTMLModule/ImageTest.php | 6 +- tests/HTMLPurifier/HTMLModule/ObjectTest.php | 4 +- .../HTMLModule/ProprietaryTest.php | 2 +- tests/HTMLPurifier/HTMLModule/RubyTest.php | 2 +- .../HTMLPurifier/HTMLModule/SafeEmbedTest.php | 2 +- .../HTMLModule/SafeObjectTest.php | 2 +- .../HTMLPurifier/HTMLModule/ScriptingTest.php | 6 +- tests/HTMLPurifier/HTMLModuleManagerTest.php | 6 +- tests/HTMLPurifier/HTMLT.php | 2 +- tests/HTMLPurifier/Harness.php | 2 +- tests/HTMLPurifier/IDAccumulatorTest.php | 2 +- .../Injector/AutoParagraphTest.php | 6 +- .../Injector/DisplayLinkURITest.php | 2 +- tests/HTMLPurifier/Injector/LinkifyTest.php | 4 +- .../Injector/PurifierLinkifyTest.php | 6 +- .../HTMLPurifier/Injector/RemoveEmptyTest.php | 6 +- .../HTMLPurifier/Injector/SafeObjectTest.php | 4 +- tests/HTMLPurifier/LanguageFactoryTest.php | 8 +- tests/HTMLPurifier/LexerTest.php | 12 +- .../HTMLPurifier/Strategy/FixNestingTest.php | 14 +- .../MakeWellFormed/EndInsertInjectorTest.php | 2 +- .../MakeWellFormed/EndRewindInjectorTest.php | 4 +- .../MakeWellFormed/SkipInjectorTest.php | 4 +- .../Strategy/MakeWellFormedTest.php | 2 +- .../Strategy/MakeWellFormed_ErrorsTest.php | 4 +- .../Strategy/MakeWellFormed_InjectorTest.php | 16 +- .../Strategy/RemoveForeignElementsTest.php | 18 +- .../RemoveForeignElements_ErrorsTest.php | 8 +- .../RemoveForeignElements_TidyTest.php | 4 +- .../Strategy/ValidateAttributesTest.php | 26 +- .../Strategy/ValidateAttributes_IDTest.php | 6 +- .../Strategy/ValidateAttributes_TidyTest.php | 2 +- tests/HTMLPurifier/URIDefinitionTest.php | 10 +- .../URIFilter/DisableExternalTest.php | 8 +- .../URIFilter/HostBlacklistTest.php | 6 +- .../URIFilter/MakeAbsoluteTest.php | 2 +- tests/HTMLPurifier/URIFilter/MungeTest.php | 6 +- tests/HTMLPurifier/URITest.php | 4 +- tests/HTMLPurifierTest.php | 4 +- 106 files changed, 504 insertions(+), 815 deletions(-) create mode 100644 maintenance/update-config.php diff --git a/configdoc/usage.xml b/configdoc/usage.xml index f89637d6..3967607e 100644 --- a/configdoc/usage.xml +++ b/configdoc/usage.xml @@ -1,402 +1,2 @@ - - - - 131 - - - 81 - - - 53 - 73 - 348 - - - 47 - - - - - 157 - - - - - 214 - - - - - 218 - - - - - 222 - - - - - 275 - - - - - 49 - - - - - 83 - - - - - 85 - - - - - 88 - - - - - 93 - - - - - 267 - 300 - - - - - 272 - 308 - - - - - 304 - - - - - 45 - - - - - 46 - - - - - 75 - - - - - 89 - - - - - 222 - - - - - 230 - - - - - 247 - - - - - 248 - - - - - 251 - - - - - 337 - - - - - 338 - - - - - 202 - - - 258 - - - 27 - - - 36 - - - 23 - - - - - 209 - - - - - 210 - - - - - 221 - - - - - 226 - - - - - 229 - - - - - 26 - - - - - 88 - - - - - 76 - - - - - 80 - - - 48 - - - - - 267 - - - - - 64 - - - - - 65 - - - - - 72 - - - - - 42 - - - - - 43 - - - - - 28 - - - - - 12 - - - 12 - - - - - 15 - - - - - 20 - - - - - 26 - - - - - 28 - 31 - - - - - 54 - - - - - 13 - - - - - 18 - - - 20 - - - - - 19 - - - - - 25 - - - - - 32 - - - - - 62 - - - - - 91 - - - - - 41 - - - - - 65 - - - - - 123 - - - - - 14 - - - 13 - - - 19 - - - - - 45 - - - - - 49 - - - - - 50 - - - - - 15 - - - - - 44 - - - - - 70 - - - - - 45 - - - 19 - - - - - 25 - - - - - 26 - - - - - 8 - - - - - 14 - - - - - 15 - - - + diff --git a/docs/dev-config-bcbreaks.txt b/docs/dev-config-bcbreaks.txt index 3969ab65..a548b120 100644 --- a/docs/dev-config-bcbreaks.txt +++ b/docs/dev-config-bcbreaks.txt @@ -33,7 +33,7 @@ look something like %Filter.YouTube.Blacklist. While you could technically set it with ('HTML', 'YouTube.Blacklist'), the logical extension ('HTML', 'YouTube', 'Blacklist') does not work. -[more changes coming] +The old API will still work, but will emit E_USER_NOTICEs. diff --git a/docs/examples/basic.php b/docs/examples/basic.php index d9b99ba2..b51096d2 100644 --- a/docs/examples/basic.php +++ b/docs/examples/basic.php @@ -8,8 +8,8 @@ require_once '../../library/HTMLPurifier.auto.php'; $config = HTMLPurifier_Config::createDefault(); // configuration goes here: -$config->set('Core', 'Encoding', 'UTF-8'); // replace with your encoding -$config->set('HTML', 'Doctype', 'XHTML 1.0 Transitional'); // replace with your doctype +$config->set('Core.Encoding', 'UTF-8'); // replace with your encoding +$config->set('HTML.Doctype', 'XHTML 1.0 Transitional'); // replace with your doctype $purifier = new HTMLPurifier($config); diff --git a/library/HTMLPurifier.kses.php b/library/HTMLPurifier.kses.php index 24bef74a..3143feb1 100644 --- a/library/HTMLPurifier.kses.php +++ b/library/HTMLPurifier.kses.php @@ -17,11 +17,11 @@ function kses($string, $allowed_html, $allowed_protocols = null) { $allowed_attributes["$element.$attribute"] = true; } } - $config->set('HTML', 'AllowedElements', $allowed_elements); - $config->set('HTML', 'AllowedAttributes', $allowed_attributes); + $config->set('HTML.AllowedElements', $allowed_elements); + $config->set('HTML.AllowedAttributes', $allowed_attributes); $allowed_schemes = array(); if ($allowed_protocols !== null) { - $config->set('URI', 'AllowedSchemes', $allowed_protocols); + $config->set('URI.AllowedSchemes', $allowed_protocols); } $purifier = new HTMLPurifier($config); return $purifier->purify($string); diff --git a/library/HTMLPurifier.php b/library/HTMLPurifier.php index 4b1eddec..64ae1487 100644 --- a/library/HTMLPurifier.php +++ b/library/HTMLPurifier.php @@ -128,7 +128,7 @@ class HTMLPurifier $context->register('Generator', $this->generator); // set up global context variables - if ($config->get('Core', 'CollectErrors')) { + if ($config->get('Core.CollectErrors')) { // may get moved out if other facilities use it $language_factory = HTMLPurifier_LanguageFactory::instance(); $language = $language_factory->create($config, $context); diff --git a/library/HTMLPurifier/AttrDef/CSS/Color.php b/library/HTMLPurifier/AttrDef/CSS/Color.php index 14c6594b..07f95a67 100644 --- a/library/HTMLPurifier/AttrDef/CSS/Color.php +++ b/library/HTMLPurifier/AttrDef/CSS/Color.php @@ -9,7 +9,7 @@ class HTMLPurifier_AttrDef_CSS_Color extends HTMLPurifier_AttrDef public function validate($color, $config, $context) { static $colors = null; - if ($colors === null) $colors = $config->get('Core', 'ColorKeywords'); + if ($colors === null) $colors = $config->get('Core.ColorKeywords'); $color = trim($color); if ($color === '') return false; diff --git a/library/HTMLPurifier/AttrDef/HTML/Color.php b/library/HTMLPurifier/AttrDef/HTML/Color.php index 5311a3c6..d01e2045 100644 --- a/library/HTMLPurifier/AttrDef/HTML/Color.php +++ b/library/HTMLPurifier/AttrDef/HTML/Color.php @@ -9,7 +9,7 @@ class HTMLPurifier_AttrDef_HTML_Color extends HTMLPurifier_AttrDef public function validate($string, $config, $context) { static $colors = null; - if ($colors === null) $colors = $config->get('Core', 'ColorKeywords'); + if ($colors === null) $colors = $config->get('Core.ColorKeywords'); $string = trim($string); diff --git a/library/HTMLPurifier/AttrDef/HTML/FrameTarget.php b/library/HTMLPurifier/AttrDef/HTML/FrameTarget.php index bd281a89..ae6ea7c0 100644 --- a/library/HTMLPurifier/AttrDef/HTML/FrameTarget.php +++ b/library/HTMLPurifier/AttrDef/HTML/FrameTarget.php @@ -12,7 +12,7 @@ class HTMLPurifier_AttrDef_HTML_FrameTarget extends HTMLPurifier_AttrDef_Enum public function __construct() {} public function validate($string, $config, $context) { - if ($this->valid_values === false) $this->valid_values = $config->get('Attr', 'AllowedFrameTargets'); + if ($this->valid_values === false) $this->valid_values = $config->get('Attr.AllowedFrameTargets'); return parent::validate($string, $config, $context); } diff --git a/library/HTMLPurifier/AttrDef/HTML/ID.php b/library/HTMLPurifier/AttrDef/HTML/ID.php index 7c5c169c..81d03762 100644 --- a/library/HTMLPurifier/AttrDef/HTML/ID.php +++ b/library/HTMLPurifier/AttrDef/HTML/ID.php @@ -17,18 +17,18 @@ class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef public function validate($id, $config, $context) { - if (!$config->get('Attr', 'EnableID')) return false; + if (!$config->get('Attr.EnableID')) return false; $id = trim($id); // trim it first if ($id === '') return false; - $prefix = $config->get('Attr', 'IDPrefix'); + $prefix = $config->get('Attr.IDPrefix'); if ($prefix !== '') { - $prefix .= $config->get('Attr', 'IDPrefixLocal'); + $prefix .= $config->get('Attr.IDPrefixLocal'); // prevent re-appending the prefix if (strpos($id, $prefix) !== 0) $id = $prefix . $id; - } elseif ($config->get('Attr', 'IDPrefixLocal') !== '') { + } elseif ($config->get('Attr.IDPrefixLocal') !== '') { trigger_error('%Attr.IDPrefixLocal cannot be used unless '. '%Attr.IDPrefix is set', E_USER_WARNING); } @@ -51,7 +51,7 @@ class HTMLPurifier_AttrDef_HTML_ID extends HTMLPurifier_AttrDef $result = ($trim === ''); } - $regexp = $config->get('Attr', 'IDBlacklistRegexp'); + $regexp = $config->get('Attr.IDBlacklistRegexp'); if ($regexp && preg_match($regexp, $id)) { return false; } diff --git a/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php b/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php index 8a0da0c8..76d25ed0 100644 --- a/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php +++ b/library/HTMLPurifier/AttrDef/HTML/LinkTypes.php @@ -27,7 +27,7 @@ class HTMLPurifier_AttrDef_HTML_LinkTypes extends HTMLPurifier_AttrDef public function validate($string, $config, $context) { - $allowed = $config->get('Attr', $this->name); + $allowed = $config->get('Attr.' . $this->name); if (empty($allowed)) return false; $string = $this->parseCDATA($string); diff --git a/library/HTMLPurifier/AttrDef/URI.php b/library/HTMLPurifier/AttrDef/URI.php index 93d2f0bb..01a6d83e 100644 --- a/library/HTMLPurifier/AttrDef/URI.php +++ b/library/HTMLPurifier/AttrDef/URI.php @@ -25,7 +25,7 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef public function validate($uri, $config, $context) { - if ($config->get('URI', 'Disable')) return false; + if ($config->get('URI.Disable')) return false; $uri = $this->parseCDATA($uri); diff --git a/library/HTMLPurifier/AttrTransform/BdoDir.php b/library/HTMLPurifier/AttrTransform/BdoDir.php index 40310b91..4d1a0566 100644 --- a/library/HTMLPurifier/AttrTransform/BdoDir.php +++ b/library/HTMLPurifier/AttrTransform/BdoDir.php @@ -10,7 +10,7 @@ class HTMLPurifier_AttrTransform_BdoDir extends HTMLPurifier_AttrTransform public function transform($attr, $config, $context) { if (isset($attr['dir'])) return $attr; - $attr['dir'] = $config->get('Attr', 'DefaultTextDir'); + $attr['dir'] = $config->get('Attr.DefaultTextDir'); return $attr; } diff --git a/library/HTMLPurifier/AttrTransform/ImgRequired.php b/library/HTMLPurifier/AttrTransform/ImgRequired.php index 25c9403c..a219479a 100644 --- a/library/HTMLPurifier/AttrTransform/ImgRequired.php +++ b/library/HTMLPurifier/AttrTransform/ImgRequired.php @@ -15,21 +15,21 @@ class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform $src = true; if (!isset($attr['src'])) { - if ($config->get('Core', 'RemoveInvalidImg')) return $attr; - $attr['src'] = $config->get('Attr', 'DefaultInvalidImage'); + if ($config->get('Core.RemoveInvalidImg')) return $attr; + $attr['src'] = $config->get('Attr.DefaultInvalidImage'); $src = false; } if (!isset($attr['alt'])) { if ($src) { - $alt = $config->get('Attr', 'DefaultImageAlt'); + $alt = $config->get('Attr.DefaultImageAlt'); if ($alt === null) { $attr['alt'] = basename($attr['src']); } else { $attr['alt'] = $alt; } } else { - $attr['alt'] = $config->get('Attr', 'DefaultInvalidImageAlt'); + $attr['alt'] = $config->get('Attr.DefaultInvalidImageAlt'); } } diff --git a/library/HTMLPurifier/CSSDefinition.php b/library/HTMLPurifier/CSSDefinition.php index 1a180573..6a2e6f56 100644 --- a/library/HTMLPurifier/CSSDefinition.php +++ b/library/HTMLPurifier/CSSDefinition.php @@ -154,7 +154,7 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition new HTMLPurifier_AttrDef_CSS_Percentage(true), new HTMLPurifier_AttrDef_Enum(array('auto')) )); - $max = $config->get('CSS', 'MaxImgLength'); + $max = $config->get('CSS.MaxImgLength'); $this->info['width'] = $this->info['height'] = @@ -211,15 +211,15 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition // partial support $this->info['white-space'] = new HTMLPurifier_AttrDef_Enum(array('nowrap')); - if ($config->get('CSS', 'Proprietary')) { + if ($config->get('CSS.Proprietary')) { $this->doSetupProprietary($config); } - if ($config->get('CSS', 'AllowTricky')) { + if ($config->get('CSS.AllowTricky')) { $this->doSetupTricky($config); } - $allow_important = $config->get('CSS', 'AllowImportant'); + $allow_important = $config->get('CSS.AllowImportant'); // wrap all attr-defs with decorator that handles !important foreach ($this->info as $k => $v) { $this->info[$k] = new HTMLPurifier_AttrDef_CSS_ImportantDecorator($v, $allow_important); @@ -272,7 +272,7 @@ class HTMLPurifier_CSSDefinition extends HTMLPurifier_Definition // setup allowed elements $support = "(for information on implementing this, see the ". "support forums) "; - $allowed_attributes = $config->get('CSS', 'AllowedProperties'); + $allowed_attributes = $config->get('CSS.AllowedProperties'); if ($allowed_attributes !== null) { foreach ($this->info as $name => $d) { if(!isset($allowed_attributes[$name])) unset($this->info[$name]); diff --git a/library/HTMLPurifier/ChildDef/Required.php b/library/HTMLPurifier/ChildDef/Required.php index c3e748b2..4889f249 100644 --- a/library/HTMLPurifier/ChildDef/Required.php +++ b/library/HTMLPurifier/ChildDef/Required.php @@ -59,7 +59,7 @@ class HTMLPurifier_ChildDef_Required extends HTMLPurifier_ChildDef $all_whitespace = true; // some configuration - $escape_invalid_children = $config->get('Core', 'EscapeInvalidChildren'); + $escape_invalid_children = $config->get('Core.EscapeInvalidChildren'); // generator $gen = new HTMLPurifier_Generator($config, $context); diff --git a/library/HTMLPurifier/Config.php b/library/HTMLPurifier/Config.php index cbb65591..ab925c91 100644 --- a/library/HTMLPurifier/Config.php +++ b/library/HTMLPurifier/Config.php @@ -68,6 +68,18 @@ class HTMLPurifier_Config */ protected $plist; + /** + * Whether or not a set is taking place due to an + * alias lookup. + */ + private $aliasMode; + + /** + * Set to false if you do not want line and file numbers in errors + * (useful when unit testing) + */ + public $chatty = true; + /** * @param $definition HTMLPurifier_ConfigSchema that defines what directives * are allowed. @@ -117,18 +129,21 @@ class HTMLPurifier_Config * @param $namespace String namespace * @param $key String key */ - public function get($namespace, $directive) { - $key = "$namespace.$directive"; + public function get($key, $a = null) { + if ($a !== null) { + $this->triggerError("Using deprecated API: use \$config->get('$key.$a') instead", E_USER_WARNING); + $key = "$key.$a"; + } if (!$this->finalized) $this->autoFinalize ? $this->finalize() : $this->plist->squash(true); if (!isset($this->def->info[$key])) { // can't add % due to SimpleTest bug - trigger_error('Cannot retrieve value of undefined directive ' . htmlspecialchars($key), + $this->triggerError('Cannot retrieve value of undefined directive ' . htmlspecialchars($key), E_USER_WARNING); return; } if (isset($this->def->info[$key]->isAlias)) { $d = $this->def->info[$key]; - trigger_error('Cannot get value from aliased directive, use real name ' . $d->key, + $this->triggerError('Cannot get value from aliased directive, use real name ' . $d->key, E_USER_ERROR); return; } @@ -143,7 +158,7 @@ class HTMLPurifier_Config if (!$this->finalized) $this->autoFinalize ? $this->finalize() : $this->plist->squash(true); $full = $this->getAll(); if (!isset($full[$namespace])) { - trigger_error('Cannot retrieve undefined namespace ' . htmlspecialchars($namespace), + $this->triggerError('Cannot retrieve undefined namespace ' . htmlspecialchars($namespace), E_USER_WARNING); return; } @@ -196,26 +211,34 @@ class HTMLPurifier_Config * @param $key String key * @param $value Mixed value */ - public function set($namespace, $directive, $value, $from_alias = false) { - $key = "$namespace.$directive"; + public function set($key, $value, $a = null) { + if (strpos($key, '.') === false) { + $namespace = $key; + $directive = $value; + $value = $a; + $key = "$key.$directive"; + $this->triggerError("Using deprecated API: use \$config->set('$key', ...) instead", E_USER_NOTICE); + } else { + list($namespace) = explode('.', $key); + } if ($this->isFinalized('Cannot set directive after finalization')) return; if (!isset($this->def->info[$key])) { - trigger_error('Cannot set undefined directive ' . htmlspecialchars($key) . ' to value', + $this->triggerError('Cannot set undefined directive ' . htmlspecialchars($key) . ' to value', E_USER_WARNING); return; } $def = $this->def->info[$key]; if (isset($def->isAlias)) { - if ($from_alias) { - trigger_error('Double-aliases not allowed, please fix '. + if ($this->aliasMode) { + $this->triggerError('Double-aliases not allowed, please fix '. 'ConfigSchema bug with' . $key, E_USER_ERROR); return; } - list($alias_namespace, $alias_directive) = explode('.', $def->key, 2); - $this->set($alias_namespace, $alias_directive, - $value, true); - trigger_error("$key is an alias, preferred directive name is {$def->key}", E_USER_NOTICE); + $this->aliasMode = true; + $this->set($def->key, $value); + $this->aliasMode = false; + $this->triggerError("$key is an alias, preferred directive name is {$def->key}", E_USER_NOTICE); return; } @@ -233,7 +256,7 @@ class HTMLPurifier_Config try { $value = $this->parser->parse($value, $type, $allow_null); } catch (HTMLPurifier_VarParserException $e) { - trigger_error('Value for ' . $key . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING); + $this->triggerError('Value for ' . $key . ' is of invalid type, should be ' . HTMLPurifier_VarParser::getTypeName($type), E_USER_WARNING); return; } if (is_string($value) && is_object($def)) { @@ -243,7 +266,7 @@ class HTMLPurifier_Config } // check to see if the value is allowed if (isset($def->allowed) && !isset($def->allowed[$value])) { - trigger_error('Value not supported, valid values are: ' . + $this->triggerError('Value not supported, valid values are: ' . $this->_listify($def->allowed), E_USER_WARNING); return; } @@ -330,7 +353,7 @@ class HTMLPurifier_Config } // quick abort if raw if ($raw) { - if (is_null($this->get($type, 'DefinitionID'))) { + if (is_null($this->get($type . '.DefinitionID'))) { // fatally error out if definition ID not set throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %$type.DefinitionID"); } @@ -354,12 +377,12 @@ class HTMLPurifier_Config $key = str_replace('_', '.', $key); if (strpos($key, '.') !== false) { list($namespace, $directive) = explode(".", $key, 2); - $this->set($namespace, $directive, $value); + $this->set($key, $value); } else { $namespace = $key; $namespace_values = $value; foreach ($namespace_values as $directive => $value) { - $this->set($namespace, $directive, $value); + $this->set($namespace .'.'. $directive, $value); } } } @@ -472,7 +495,7 @@ class HTMLPurifier_Config */ public function isFinalized($error = false) { if ($this->finalized && $error) { - trigger_error($error, E_USER_ERROR); + $this->triggerError($error, E_USER_ERROR); } return $this->finalized; } @@ -492,6 +515,23 @@ class HTMLPurifier_Config $this->finalized = true; } + /** + * Produces a nicely formatted error message by supplying the + * stack frame information from two levels up and OUTSIDE of + * HTMLPurifier_Config. + */ + protected function triggerError($msg, $no) { + // determine previous stack frame + $backtrace = debug_backtrace(); + if ($this->chatty && isset($backtrace[1])) { + $frame = $backtrace[1]; + $extra = " on line {$frame['line']} in file {$frame['file']}"; + } else { + $extra = ''; + } + trigger_error($msg . $extra, $no); + } + } // vim: et sw=4 sts=4 diff --git a/library/HTMLPurifier/DefinitionCache.php b/library/HTMLPurifier/DefinitionCache.php index fa5a087b..c6e1e388 100644 --- a/library/HTMLPurifier/DefinitionCache.php +++ b/library/HTMLPurifier/DefinitionCache.php @@ -28,7 +28,7 @@ abstract class HTMLPurifier_DefinitionCache public function generateKey($config) { return $config->version . ',' . // possibly replace with function calls $config->getBatchSerial($this->type) . ',' . - $config->get($this->type, 'DefinitionRev'); + $config->get($this->type . '.DefinitionRev'); } /** @@ -46,7 +46,7 @@ abstract class HTMLPurifier_DefinitionCache // versions match, ids match, check revision number if ( $hash == $config->getBatchSerial($this->type) && - $revision < $config->get($this->type, 'DefinitionRev') + $revision < $config->get($this->type . '.DefinitionRev') ) return true; return false; } diff --git a/library/HTMLPurifier/DefinitionCache/Serializer.php b/library/HTMLPurifier/DefinitionCache/Serializer.php index acbbe2c3..7a6aa93f 100644 --- a/library/HTMLPurifier/DefinitionCache/Serializer.php +++ b/library/HTMLPurifier/DefinitionCache/Serializer.php @@ -88,7 +88,7 @@ class HTMLPurifier_DefinitionCache_Serializer extends * @todo Make protected */ public function generateBaseDirectoryPath($config) { - $base = $config->get('Cache', 'SerializerPath'); + $base = $config->get('Cache.SerializerPath'); $base = is_null($base) ? HTMLPURIFIER_PREFIX . '/HTMLPurifier/DefinitionCache/Serializer' : $base; return $base; } diff --git a/library/HTMLPurifier/DefinitionCacheFactory.php b/library/HTMLPurifier/DefinitionCacheFactory.php index 3adefbb6..a6ead628 100644 --- a/library/HTMLPurifier/DefinitionCacheFactory.php +++ b/library/HTMLPurifier/DefinitionCacheFactory.php @@ -46,7 +46,7 @@ class HTMLPurifier_DefinitionCacheFactory * @param $config Instance of HTMLPurifier_Config */ public function create($type, $config) { - $method = $config->get('Cache', 'DefinitionImpl'); + $method = $config->get('Cache.DefinitionImpl'); if ($method === null) { return new HTMLPurifier_DefinitionCache_Null($type); } diff --git a/library/HTMLPurifier/DoctypeRegistry.php b/library/HTMLPurifier/DoctypeRegistry.php index d6552aa5..86049e93 100644 --- a/library/HTMLPurifier/DoctypeRegistry.php +++ b/library/HTMLPurifier/DoctypeRegistry.php @@ -80,17 +80,17 @@ class HTMLPurifier_DoctypeRegistry */ public function getDoctypeFromConfig($config) { // recommended test - $doctype = $config->get('HTML', 'Doctype'); + $doctype = $config->get('HTML.Doctype'); if (!empty($doctype)) return $doctype; - $doctype = $config->get('HTML', 'CustomDoctype'); + $doctype = $config->get('HTML.CustomDoctype'); if (!empty($doctype)) return $doctype; // backwards-compatibility - if ($config->get('HTML', 'XHTML')) { + if ($config->get('HTML.XHTML')) { $doctype = 'XHTML 1.0'; } else { $doctype = 'HTML 4.01'; } - if ($config->get('HTML', 'Strict')) { + if ($config->get('HTML.Strict')) { $doctype .= ' Strict'; } else { $doctype .= ' Transitional'; diff --git a/library/HTMLPurifier/Encoder.php b/library/HTMLPurifier/Encoder.php index 79a42d26..201afc6e 100644 --- a/library/HTMLPurifier/Encoder.php +++ b/library/HTMLPurifier/Encoder.php @@ -264,12 +264,12 @@ class HTMLPurifier_Encoder * Converts a string to UTF-8 based on configuration. */ public static function convertToUTF8($str, $config, $context) { - $encoding = $config->get('Core', 'Encoding'); + $encoding = $config->get('Core.Encoding'); if ($encoding === 'utf-8') return $str; static $iconv = null; if ($iconv === null) $iconv = function_exists('iconv'); set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler')); - if ($iconv && !$config->get('Test', 'ForceNoIconv')) { + if ($iconv && !$config->get('Test.ForceNoIconv')) { $str = iconv($encoding, 'utf-8//IGNORE', $str); if ($str === false) { // $encoding is not a valid encoding @@ -297,15 +297,15 @@ class HTMLPurifier_Encoder * characters being omitted. */ public static function convertFromUTF8($str, $config, $context) { - $encoding = $config->get('Core', 'Encoding'); + $encoding = $config->get('Core.Encoding'); if ($encoding === 'utf-8') return $str; static $iconv = null; if ($iconv === null) $iconv = function_exists('iconv'); - if ($escape = $config->get('Core', 'EscapeNonASCIICharacters')) { + if ($escape = $config->get('Core.EscapeNonASCIICharacters')) { $str = HTMLPurifier_Encoder::convertToASCIIDumbLossless($str); } set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler')); - if ($iconv && !$config->get('Test', 'ForceNoIconv')) { + if ($iconv && !$config->get('Test.ForceNoIconv')) { // Undo our previous fix in convertToUTF8, otherwise iconv will barf $ascii_fix = HTMLPurifier_Encoder::testEncodingSupportsASCII($encoding); if (!$escape && !empty($ascii_fix)) { diff --git a/library/HTMLPurifier/Filter/ExtractStyleBlocks.php b/library/HTMLPurifier/Filter/ExtractStyleBlocks.php index 970f9e0c..94dd598d 100644 --- a/library/HTMLPurifier/Filter/ExtractStyleBlocks.php +++ b/library/HTMLPurifier/Filter/ExtractStyleBlocks.php @@ -38,7 +38,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter * @todo Extend to indicate non-text/css style blocks */ public function preFilter($html, $config, $context) { - $tidy = $config->get('FilterParam', 'ExtractStyleBlocksTidyImpl'); + $tidy = $config->get('FilterParam.ExtractStyleBlocksTidyImpl'); if ($tidy !== null) $this->_tidy = $tidy; $html = preg_replace_callback('#(.+)#isU', array($this, 'styleCallback'), $html); $style_blocks = $this->_styleMatches; @@ -62,7 +62,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter */ public function cleanCSS($css, $config, $context) { // prepare scope - $scope = $config->get('FilterParam', 'ExtractStyleBlocksScope'); + $scope = $config->get('FilterParam.ExtractStyleBlocksScope'); if ($scope !== null) { $scopes = array_map('trim', explode(',', $scope)); } else { @@ -120,7 +120,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocks extends HTMLPurifier_Filter $css = $this->_tidy->print->plain(); // we are going to escape any special characters <>& to ensure // that no funny business occurs (i.e. in a font-family prop). - if ($config->get('FilterParam', 'ExtractStyleBlocksEscaping')) { + if ($config->get('FilterParam.ExtractStyleBlocksEscaping')) { $css = str_replace( array('<', '>', '&'), array('\3C ', '\3E ', '\26 '), diff --git a/library/HTMLPurifier/Generator.php b/library/HTMLPurifier/Generator.php index a1b96b9e..24bd8a54 100644 --- a/library/HTMLPurifier/Generator.php +++ b/library/HTMLPurifier/Generator.php @@ -42,8 +42,8 @@ class HTMLPurifier_Generator */ public function __construct($config, $context) { $this->config = $config; - $this->_scriptFix = $config->get('Output', 'CommentScriptContents'); - $this->_sortAttr = $config->get('Output', 'SortAttr'); + $this->_scriptFix = $config->get('Output.CommentScriptContents'); + $this->_sortAttr = $config->get('Output.SortAttr'); $this->_def = $config->getHTMLDefinition(); $this->_xhtml = $this->_def->doctype->xml; } @@ -72,7 +72,7 @@ class HTMLPurifier_Generator } // Tidy cleanup - if (extension_loaded('tidy') && $this->config->get('Output', 'TidyFormat')) { + if (extension_loaded('tidy') && $this->config->get('Output.TidyFormat')) { $tidy = new Tidy; $tidy->parseString($html, array( 'indent'=> true, @@ -86,7 +86,7 @@ class HTMLPurifier_Generator } // Normalize newlines to system defined value - $nl = $this->config->get('Output', 'Newline'); + $nl = $this->config->get('Output.Newline'); if ($nl === null) $nl = PHP_EOL; if ($nl !== "\n") $html = str_replace("\n", $nl, $html); return $html; diff --git a/library/HTMLPurifier/HTMLDefinition.php b/library/HTMLPurifier/HTMLDefinition.php index 3368821c..44f4616f 100644 --- a/library/HTMLPurifier/HTMLDefinition.php +++ b/library/HTMLPurifier/HTMLDefinition.php @@ -219,7 +219,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition */ protected function setupConfigStuff($config) { - $block_wrapper = $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 { @@ -227,7 +227,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition E_USER_ERROR); } - $parent = $config->get('HTML', 'Parent'); + $parent = $config->get('HTML.Parent'); $def = $this->manager->getElement($parent, true); if ($def) { $this->info_parent = $parent; @@ -244,11 +244,11 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition // setup allowed elements ----------------------------------------- - $allowed_elements = $config->get('HTML', 'AllowedElements'); - $allowed_attributes = $config->get('HTML', 'AllowedAttributes'); // retrieve early + $allowed_elements = $config->get('HTML.AllowedElements'); + $allowed_attributes = $config->get('HTML.AllowedAttributes'); // retrieve early if (!is_array($allowed_elements) && !is_array($allowed_attributes)) { - $allowed = $config->get('HTML', 'Allowed'); + $allowed = $config->get('HTML.Allowed'); if (is_string($allowed)) { list($allowed_elements, $allowed_attributes) = $this->parseTinyMCEAllowedList($allowed); } @@ -334,8 +334,8 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition // setup forbidden elements --------------------------------------- - $forbidden_elements = $config->get('HTML', 'ForbiddenElements'); - $forbidden_attributes = $config->get('HTML', 'ForbiddenAttributes'); + $forbidden_elements = $config->get('HTML.ForbiddenElements'); + $forbidden_attributes = $config->get('HTML.ForbiddenAttributes'); foreach ($this->info as $tag => $info) { if (isset($forbidden_elements[$tag])) { diff --git a/library/HTMLPurifier/HTMLModule/Image.php b/library/HTMLPurifier/HTMLModule/Image.php index e6ed53ae..948d435b 100644 --- a/library/HTMLPurifier/HTMLModule/Image.php +++ b/library/HTMLPurifier/HTMLModule/Image.php @@ -11,7 +11,7 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule public $name = 'Image'; public function setup($config) { - $max = $config->get('HTML', 'MaxImgLength'); + $max = $config->get('HTML.MaxImgLength'); $img = $this->addElement( 'img', 'Inline', 'Empty', 'Common', array( @@ -24,7 +24,7 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule 'src*' => new HTMLPurifier_AttrDef_URI(true), // embedded ) ); - if ($max === null || $config->get('HTML', 'Trusted')) { + if ($max === null || $config->get('HTML.Trusted')) { $img->attr['height'] = $img->attr['width'] = 'Length'; } diff --git a/library/HTMLPurifier/HTMLModule/SafeEmbed.php b/library/HTMLPurifier/HTMLModule/SafeEmbed.php index 635e8f2d..8fc03cb1 100644 --- a/library/HTMLPurifier/HTMLModule/SafeEmbed.php +++ b/library/HTMLPurifier/HTMLModule/SafeEmbed.php @@ -10,7 +10,7 @@ class HTMLPurifier_HTMLModule_SafeEmbed extends HTMLPurifier_HTMLModule public function setup($config) { - $max = $config->get('HTML', 'MaxImgLength'); + $max = $config->get('HTML.MaxImgLength'); $embed = $this->addElement( 'embed', 'Inline', 'Empty', 'Common', array( diff --git a/library/HTMLPurifier/HTMLModule/SafeObject.php b/library/HTMLPurifier/HTMLModule/SafeObject.php index bbda7a21..33bac00c 100644 --- a/library/HTMLPurifier/HTMLModule/SafeObject.php +++ b/library/HTMLPurifier/HTMLModule/SafeObject.php @@ -16,7 +16,7 @@ class HTMLPurifier_HTMLModule_SafeObject extends HTMLPurifier_HTMLModule // These definitions are not intrinsically safe: the attribute transforms // are a vital part of ensuring safety. - $max = $config->get('HTML', 'MaxImgLength'); + $max = $config->get('HTML.MaxImgLength'); $object = $this->addElement( 'object', 'Inline', diff --git a/library/HTMLPurifier/HTMLModule/Tidy.php b/library/HTMLPurifier/HTMLModule/Tidy.php index c9d47064..21783f18 100644 --- a/library/HTMLPurifier/HTMLModule/Tidy.php +++ b/library/HTMLPurifier/HTMLModule/Tidy.php @@ -42,12 +42,12 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule $this->makeFixesForLevel($fixes); // figure out which fixes to use - $level = $config->get('HTML', 'TidyLevel'); + $level = $config->get('HTML.TidyLevel'); $fixes_lookup = $this->getFixesForLevel($level); // get custom fix declarations: these need namespace processing - $add_fixes = $config->get('HTML', 'TidyAdd'); - $remove_fixes = $config->get('HTML', 'TidyRemove'); + $add_fixes = $config->get('HTML.TidyAdd'); + $remove_fixes = $config->get('HTML.TidyRemove'); foreach ($fixes as $name => $fix) { // needs to be refactored a little to implement globbing diff --git a/library/HTMLPurifier/HTMLModuleManager.php b/library/HTMLPurifier/HTMLModuleManager.php index 78f38781..f5c4a1d2 100644 --- a/library/HTMLPurifier/HTMLModuleManager.php +++ b/library/HTMLPurifier/HTMLModuleManager.php @@ -199,15 +199,15 @@ class HTMLPurifier_HTMLModuleManager */ public function setup($config) { - $this->trusted = $config->get('HTML', 'Trusted'); + $this->trusted = $config->get('HTML.Trusted'); // generate $this->doctype = $this->doctypes->make($config); $modules = $this->doctype->modules; // take out the default modules that aren't allowed - $lookup = $config->get('HTML', 'AllowedModules'); - $special_cases = $config->get('HTML', 'CoreModules'); + $lookup = $config->get('HTML.AllowedModules'); + $special_cases = $config->get('HTML.CoreModules'); if (is_array($lookup)) { foreach ($modules as $k => $m) { @@ -218,15 +218,15 @@ class HTMLPurifier_HTMLModuleManager // add proprietary module (this gets special treatment because // it is completely removed from doctypes, etc.) - if ($config->get('HTML', 'Proprietary')) { + if ($config->get('HTML.Proprietary')) { $modules[] = 'Proprietary'; } // add SafeObject/Safeembed modules - if ($config->get('HTML', 'SafeObject')) { + if ($config->get('HTML.SafeObject')) { $modules[] = 'SafeObject'; } - if ($config->get('HTML', 'SafeEmbed')) { + if ($config->get('HTML.SafeEmbed')) { $modules[] = 'SafeEmbed'; } diff --git a/library/HTMLPurifier/IDAccumulator.php b/library/HTMLPurifier/IDAccumulator.php index d546cd75..73215295 100644 --- a/library/HTMLPurifier/IDAccumulator.php +++ b/library/HTMLPurifier/IDAccumulator.php @@ -23,7 +23,7 @@ class HTMLPurifier_IDAccumulator */ public static function build($config, $context) { $id_accumulator = new HTMLPurifier_IDAccumulator(); - $id_accumulator->load($config->get('Attr', 'IDBlacklist')); + $id_accumulator->load($config->get('Attr.IDBlacklist')); return $id_accumulator; } diff --git a/library/HTMLPurifier/Injector/PurifierLinkify.php b/library/HTMLPurifier/Injector/PurifierLinkify.php index 3c706a33..a8549688 100644 --- a/library/HTMLPurifier/Injector/PurifierLinkify.php +++ b/library/HTMLPurifier/Injector/PurifierLinkify.php @@ -12,7 +12,7 @@ class HTMLPurifier_Injector_PurifierLinkify extends HTMLPurifier_Injector public $needed = array('a' => array('href')); public function prepare($config, $context) { - $this->docURL = $config->get('AutoFormatParam', 'PurifierLinkifyDocURL'); + $this->docURL = $config->get('AutoFormatParam.PurifierLinkifyDocURL'); return parent::prepare($config, $context); } diff --git a/library/HTMLPurifier/LanguageFactory.php b/library/HTMLPurifier/LanguageFactory.php index baa4422e..134ef8c7 100644 --- a/library/HTMLPurifier/LanguageFactory.php +++ b/library/HTMLPurifier/LanguageFactory.php @@ -85,7 +85,7 @@ class HTMLPurifier_LanguageFactory // validate language code if ($code === false) { $code = $this->validator->validate( - $config->get('Core', 'Language'), $config, $context + $config->get('Core.Language'), $config, $context ); } else { $code = $this->validator->validate($code, $config, $context); diff --git a/library/HTMLPurifier/Lexer.php b/library/HTMLPurifier/Lexer.php index 94588699..7cbba469 100644 --- a/library/HTMLPurifier/Lexer.php +++ b/library/HTMLPurifier/Lexer.php @@ -73,12 +73,12 @@ class HTMLPurifier_Lexer HTMLPurifier_Lexer::create() is deprecated, please instead use %Core.LexerImpl", E_USER_WARNING); } else { - $lexer = $config->get('Core', 'LexerImpl'); + $lexer = $config->get('Core.LexerImpl'); } $needs_tracking = - $config->get('Core', 'MaintainLineNumbers') || - $config->get('Core', 'CollectErrors'); + $config->get('Core.MaintainLineNumbers') || + $config->get('Core.CollectErrors'); $inst = null; if (is_object($lexer)) { @@ -255,7 +255,7 @@ class HTMLPurifier_Lexer $html = str_replace("\r\n", "\n", $html); $html = str_replace("\r", "\n", $html); - if ($config->get('HTML', 'Trusted')) { + if ($config->get('HTML.Trusted')) { // escape convoluted CDATA $html = $this->escapeCommentedCDATA($html); } @@ -264,7 +264,7 @@ class HTMLPurifier_Lexer $html = $this->escapeCDATA($html); // extract body from document if applicable - if ($config->get('Core', 'ConvertDocumentToFragment')) { + if ($config->get('Core.ConvertDocumentToFragment')) { $html = $this->extractBody($html); } diff --git a/library/HTMLPurifier/Lexer/DOMLex.php b/library/HTMLPurifier/Lexer/DOMLex.php index 0db3974b..20dc2ed4 100644 --- a/library/HTMLPurifier/Lexer/DOMLex.php +++ b/library/HTMLPurifier/Lexer/DOMLex.php @@ -41,7 +41,7 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer // attempt to armor stray angled brackets that cannot possibly // form tags and thus are probably being used as emoticons - if ($config->get('Core', 'AggressivelyFixLt')) { + if ($config->get('Core.AggressivelyFixLt')) { $char = '[^a-z!\/]'; $comment = "/|\z)/is"; $html = preg_replace_callback($comment, array($this, 'callbackArmorCommentEntities'), $html); diff --git a/library/HTMLPurifier/Lexer/DirectLex.php b/library/HTMLPurifier/Lexer/DirectLex.php index bfca4533..439409d0 100644 --- a/library/HTMLPurifier/Lexer/DirectLex.php +++ b/library/HTMLPurifier/Lexer/DirectLex.php @@ -33,7 +33,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer // special normalization for script tags without any armor // our "armor" heurstic is a < sign any number of whitespaces after // the first script tag - if ($config->get('HTML', 'Trusted')) { + if ($config->get('HTML.Trusted')) { $html = preg_replace_callback('#(]*>)(\s*[^<].+?)()#si', array($this, 'scriptCallback'), $html); } @@ -45,12 +45,12 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer $array = array(); // result array // This is also treated to mean maintain *column* numbers too - $maintain_line_numbers = $config->get('Core', 'MaintainLineNumbers'); + $maintain_line_numbers = $config->get('Core.MaintainLineNumbers'); if ($maintain_line_numbers === null) { // automatically determine line numbering by checking // if error collection is on - $maintain_line_numbers = $config->get('Core', 'CollectErrors'); + $maintain_line_numbers = $config->get('Core.CollectErrors'); } if ($maintain_line_numbers) { @@ -67,10 +67,10 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer $nl = "\n"; // how often to manually recalculate. This will ALWAYS be right, // but it's pretty wasteful. Set to 0 to turn off - $synchronize_interval = $config->get('Core', 'DirectLexLineNumberSyncInterval'); + $synchronize_interval = $config->get('Core.DirectLexLineNumberSyncInterval'); $e = false; - if ($config->get('Core', 'CollectErrors')) { + if ($config->get('Core.CollectErrors')) { $e =& $context->get('ErrorCollector'); } @@ -345,7 +345,7 @@ class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer if ($string == '') return array(); // no attributes $e = false; - if ($config->get('Core', 'CollectErrors')) { + if ($config->get('Core.CollectErrors')) { $e =& $context->get('ErrorCollector'); } diff --git a/library/HTMLPurifier/Printer/ConfigForm.php b/library/HTMLPurifier/Printer/ConfigForm.php index 24e8c691..02aa6568 100644 --- a/library/HTMLPurifier/Printer/ConfigForm.php +++ b/library/HTMLPurifier/Printer/ConfigForm.php @@ -91,7 +91,7 @@ class HTMLPurifier_Printer_ConfigForm extends HTMLPurifier_Printer $all = array(); foreach ($allowed as $key) { list($ns, $directive) = $key; - $all[$ns][$directive] = $config->get($ns, $directive); + $all[$ns][$directive] = $config->get($ns .'.'. $directive); } $ret = ''; diff --git a/library/HTMLPurifier/Strategy/MakeWellFormed.php b/library/HTMLPurifier/Strategy/MakeWellFormed.php index 0ec811f8..82642946 100644 --- a/library/HTMLPurifier/Strategy/MakeWellFormed.php +++ b/library/HTMLPurifier/Strategy/MakeWellFormed.php @@ -42,7 +42,7 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy // local variables $generator = new HTMLPurifier_Generator($config, $context); - $escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags'); + $escape_invalid_tags = $config->get('Core.EscapeInvalidTags'); $e = $context->get('ErrorCollector', true); $t = false; // token index $i = false; // injector index diff --git a/library/HTMLPurifier/Strategy/RemoveForeignElements.php b/library/HTMLPurifier/Strategy/RemoveForeignElements.php index d30e456d..cf3a33e4 100644 --- a/library/HTMLPurifier/Strategy/RemoveForeignElements.php +++ b/library/HTMLPurifier/Strategy/RemoveForeignElements.php @@ -16,14 +16,14 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy $generator = new HTMLPurifier_Generator($config, $context); $result = array(); - $escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags'); - $remove_invalid_img = $config->get('Core', 'RemoveInvalidImg'); + $escape_invalid_tags = $config->get('Core.EscapeInvalidTags'); + $remove_invalid_img = $config->get('Core.RemoveInvalidImg'); // currently only used to determine if comments should be kept - $trusted = $config->get('HTML', 'Trusted'); + $trusted = $config->get('HTML.Trusted'); - $remove_script_contents = $config->get('Core', 'RemoveScriptContents'); - $hidden_elements = $config->get('Core', 'HiddenElements'); + $remove_script_contents = $config->get('Core.RemoveScriptContents'); + $hidden_elements = $config->get('Core.HiddenElements'); // remove script contents compatibility if ($remove_script_contents === true) { @@ -44,7 +44,7 @@ class HTMLPurifier_Strategy_RemoveForeignElements extends HTMLPurifier_Strategy $context->register('CurrentToken', $token); $e = false; - if ($config->get('Core', 'CollectErrors')) { + if ($config->get('Core.CollectErrors')) { $e =& $context->get('ErrorCollector'); } diff --git a/library/HTMLPurifier/URIDefinition.php b/library/HTMLPurifier/URIDefinition.php index 183fcfc7..ea2b8fe2 100644 --- a/library/HTMLPurifier/URIDefinition.php +++ b/library/HTMLPurifier/URIDefinition.php @@ -52,7 +52,7 @@ class HTMLPurifier_URIDefinition extends HTMLPurifier_Definition protected function setupFilters($config) { foreach ($this->registeredFilters as $name => $filter) { - $conf = $config->get('URI', $name); + $conf = $config->get('URI.' . $name); if ($conf !== false && $conf !== null) { $this->addFilter($filter, $config); } @@ -61,15 +61,15 @@ class HTMLPurifier_URIDefinition extends HTMLPurifier_Definition } protected function setupMemberVariables($config) { - $this->host = $config->get('URI', 'Host'); - $base_uri = $config->get('URI', 'Base'); + $this->host = $config->get('URI.Host'); + $base_uri = $config->get('URI.Base'); if (!is_null($base_uri)) { $parser = new HTMLPurifier_URIParser(); $this->base = $parser->parse($base_uri); $this->defaultScheme = $this->base->scheme; if (is_null($this->host)) $this->host = $this->base->host; } - if (is_null($this->defaultScheme)) $this->defaultScheme = $config->get('URI', 'DefaultScheme'); + if (is_null($this->defaultScheme)) $this->defaultScheme = $config->get('URI.DefaultScheme'); } public function filter(&$uri, $config, $context) { diff --git a/library/HTMLPurifier/URIFilter/HostBlacklist.php b/library/HTMLPurifier/URIFilter/HostBlacklist.php index bac56e8b..045aa099 100644 --- a/library/HTMLPurifier/URIFilter/HostBlacklist.php +++ b/library/HTMLPurifier/URIFilter/HostBlacklist.php @@ -5,7 +5,7 @@ class HTMLPurifier_URIFilter_HostBlacklist extends HTMLPurifier_URIFilter public $name = 'HostBlacklist'; protected $blacklist = array(); public function prepare($config) { - $this->blacklist = $config->get('URI', 'HostBlacklist'); + $this->blacklist = $config->get('URI.HostBlacklist'); return true; } public function filter(&$uri, $config, $context) { diff --git a/library/HTMLPurifier/URIFilter/Munge.php b/library/HTMLPurifier/URIFilter/Munge.php index 29ed0ed1..6c66a8ee 100644 --- a/library/HTMLPurifier/URIFilter/Munge.php +++ b/library/HTMLPurifier/URIFilter/Munge.php @@ -9,10 +9,10 @@ class HTMLPurifier_URIFilter_Munge extends HTMLPurifier_URIFilter protected $replace = array(); public function prepare($config) { - $this->target = $config->get('URI', $this->name); + $this->target = $config->get('URI.' . $this->name); $this->parser = new HTMLPurifier_URIParser(); - $this->doEmbed = $config->get('URI', 'MungeResources'); - $this->secretKey = $config->get('URI', 'MungeSecretKey'); + $this->doEmbed = $config->get('URI.MungeResources'); + $this->secretKey = $config->get('URI.MungeSecretKey'); return true; } public function filter(&$uri, $config, $context) { diff --git a/library/HTMLPurifier/URISchemeRegistry.php b/library/HTMLPurifier/URISchemeRegistry.php index d24732c1..6adaf155 100644 --- a/library/HTMLPurifier/URISchemeRegistry.php +++ b/library/HTMLPurifier/URISchemeRegistry.php @@ -39,8 +39,8 @@ class HTMLPurifier_URISchemeRegistry $null = null; // for the sake of passing by reference // important, otherwise attacker could include arbitrary file - $allowed_schemes = $config->get('URI', 'AllowedSchemes'); - if (!$config->get('URI', 'OverrideAllowedSchemes') && + $allowed_schemes = $config->get('URI.AllowedSchemes'); + if (!$config->get('URI.OverrideAllowedSchemes') && !isset($allowed_schemes[$scheme]) ) { return $null; diff --git a/maintenance/update-config.php b/maintenance/update-config.php new file mode 100644 index 00000000..23e10d05 --- /dev/null +++ b/maintenance/update-config.php @@ -0,0 +1,34 @@ +#!/usr/bin/php +set and $config->get to the new + * format, as described by docs/dev-config-bcbreaks.txt + */ + +$FS = new FSTools(); +chdir(dirname(__FILE__) . '/..'); +$raw_files = $FS->globr('.', '*.php'); +foreach ($raw_files as $file) { + $file = substr($file, 2); // rm leading './' + if (strpos($file, 'library/standalone/') === 0) continue; + if (strpos($file, 'maintenance/update-config.php') === 0) continue; + if (strpos($file, 'test-settings.php') === 0) continue; + if (substr_count($file, '.') > 1) continue; // rm meta files + // process the file + $contents = file_get_contents($file); + $contents = preg_replace( + "#config->(set|get)\('(.+?)', '(.+?)'#", + "config->\\1('\\2.\\3'", + $contents + ); + if ($contents === '') continue; + file_put_contents($file, $contents); +} + + diff --git a/plugins/phorum/htmlpurifier.php b/plugins/phorum/htmlpurifier.php index 8ccc4fc4..8c50f5b0 100644 --- a/plugins/phorum/htmlpurifier.php +++ b/plugins/phorum/htmlpurifier.php @@ -274,7 +274,7 @@ function phorum_htmlpurifier_editor_after_subject() {

config; - if ($config->get('AutoFormat', 'AutoParagraph')) { + if ($config->get('AutoFormat.AutoParagraph')) { ?>

Auto-paragraphing is enabled. Double newlines will be converted to paragraphs; for single diff --git a/smoketests/attrTransform.php b/smoketests/attrTransform.php index c579664d..2dfda7f4 100644 --- a/smoketests/attrTransform.php +++ b/smoketests/attrTransform.php @@ -42,7 +42,7 @@ $xml = simplexml_load_file('attrTransform.xml'); // attr transform enabled HTML Purifier $config = HTMLPurifier_Config::createDefault(); -$config->set('HTML', 'Doctype', 'XHTML 1.0 Strict'); +$config->set('HTML.Doctype', 'XHTML 1.0 Strict'); $purifier = new HTMLPurifier($config); $title = isset($_GET['title']) ? $_GET['title'] : true; diff --git a/smoketests/basic.php b/smoketests/basic.php index 81efc409..1c361727 100644 --- a/smoketests/basic.php +++ b/smoketests/basic.php @@ -50,8 +50,8 @@ if ($page) { set('Attr', 'EnableID', true); - $config->set('HTML', 'Strict', $strict); + $config->set('Attr.EnableID', true); + $config->set('HTML.Strict', $strict); $purifier = new HTMLPurifier($config); echo $purifier->purify(file_get_contents("basic/$page.html")); } else { diff --git a/smoketests/xssAttacks.php b/smoketests/xssAttacks.php index 0c0b5dcb..2a4dd5e6 100644 --- a/smoketests/xssAttacks.php +++ b/smoketests/xssAttacks.php @@ -52,7 +52,7 @@ $xml = simplexml_load_file('xssAttacks.xml'); // programatically disallow google.com for URI evasion tests // not complete $config = HTMLPurifier_Config::createDefault(); -$config->set('URI', 'HostBlacklist', array('google.com')); +$config->set('URI.HostBlacklist', array('google.com')); $purifier = new HTMLPurifier($config); ?> diff --git a/tests/HTMLPurifier/AttrDef/CSSTest.php b/tests/HTMLPurifier/AttrDef/CSSTest.php index 70155acf..1c15a5c1 100644 --- a/tests/HTMLPurifier/AttrDef/CSSTest.php +++ b/tests/HTMLPurifier/AttrDef/CSSTest.php @@ -116,7 +116,7 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness } function testProprietary() { - $this->config->set('CSS', 'Proprietary', true); + $this->config->set('CSS.Proprietary', true); $this->assertDef('scrollbar-arrow-color:#ff0;'); $this->assertDef('scrollbar-base-color:#ff6347;'); @@ -133,12 +133,12 @@ class HTMLPurifier_AttrDef_CSSTest extends HTMLPurifier_AttrDefHarness } function testImportant() { - $this->config->set('CSS', 'AllowImportant', true); + $this->config->set('CSS.AllowImportant', true); $this->assertDef('float:left !important;'); } function testTricky() { - $this->config->set('CSS', 'AllowTricky', true); + $this->config->set('CSS.AllowTricky', true); $this->assertDef('display:none;'); $this->assertDef('visibility:visible;'); $this->assertDef('overflow:scroll;'); diff --git a/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php b/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php index 1b994f9e..7d3e24c7 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/FrameTargetTest.php @@ -16,7 +16,7 @@ class HTMLPurifier_AttrDef_HTML_FrameTargetTest extends HTMLPurifier_AttrDefHarn } function test() { - $this->config->set('Attr', 'AllowedFrameTargets', 'foo,_blank'); + $this->config->set('Attr.AllowedFrameTargets', 'foo,_blank'); $this->assertDef('', false); $this->assertDef('foo'); $this->assertDef('_blank'); diff --git a/tests/HTMLPurifier/AttrDef/HTML/IDTest.php b/tests/HTMLPurifier/AttrDef/HTML/IDTest.php index c5b3e3c9..245db16d 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/IDTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/IDTest.php @@ -8,7 +8,7 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness $id_accumulator = new HTMLPurifier_IDAccumulator(); $this->context->register('IDAccumulator', $id_accumulator); - $this->config->set('Attr', 'EnableID', true); + $this->config->set('Attr.EnableID', true); $this->def = new HTMLPurifier_AttrDef_HTML_ID(); } @@ -37,7 +37,7 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness function testPrefix() { - $this->config->set('Attr', 'IDPrefix', 'user_'); + $this->config->set('Attr.IDPrefix', 'user_'); $this->assertDef('alpha', 'user_alpha'); $this->assertDef('config->set('Attr', 'IDPrefix', 'user_'); - $this->config->set('Attr', 'IDPrefixLocal', 'story95_'); + $this->config->set('Attr.IDPrefix', 'user_'); + $this->config->set('Attr.IDPrefixLocal', 'story95_'); $this->assertDef('alpha', 'user_story95_alpha'); $this->assertDef('config->set('Attr', 'IDPrefix', ''); - $this->config->set('Attr', 'IDPrefixLocal', 'story95_'); + $this->config->set('Attr.IDPrefix', ''); + $this->config->set('Attr.IDPrefixLocal', 'story95_'); $this->expectError('%Attr.IDPrefixLocal cannot be used unless '. '%Attr.IDPrefix is set'); $this->assertDef('amherst'); @@ -96,7 +96,7 @@ class HTMLPurifier_AttrDef_HTML_IDTest extends HTMLPurifier_AttrDefHarness function testRegexp() { - $this->config->set('Attr', 'IDBlacklistRegexp', '/^g_/'); + $this->config->set('Attr.IDBlacklistRegexp', '/^g_/'); $this->assertDef('good_id'); $this->assertDef('g_bad_id', false); diff --git a/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php b/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php index eb225f6a..d90b65b1 100644 --- a/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php +++ b/tests/HTMLPurifier/AttrDef/HTML/LinkTypesTest.php @@ -6,7 +6,7 @@ class HTMLPurifier_AttrDef_HTML_LinkTypesTest extends HTMLPurifier_AttrDefHarnes function testNull() { $this->def = new HTMLPurifier_AttrDef_HTML_LinkTypes('rel'); - $this->config->set('Attr', 'AllowedRel', array('nofollow', 'foo')); + $this->config->set('Attr.AllowedRel', array('nofollow', 'foo')); $this->assertDef('', false); $this->assertDef('nofollow', true); diff --git a/tests/HTMLPurifier/AttrDef/URITest.php b/tests/HTMLPurifier/AttrDef/URITest.php index ee7ff29c..b149d1da 100644 --- a/tests/HTMLPurifier/AttrDef/URITest.php +++ b/tests/HTMLPurifier/AttrDef/URITest.php @@ -49,7 +49,7 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness } function testConfigMunge() { - $this->config->set('URI', 'Munge', 'http://www.google.com/url?q=%s'); + $this->config->set('URI.Munge', 'http://www.google.com/url?q=%s'); $this->assertDef( 'http://www.example.com/', 'http://www.google.com/url?q=http%3A%2F%2Fwww.example.com%2F' @@ -77,7 +77,7 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness function testURIDefinitionValidation() { $parser = new HTMLPurifier_URIParser(); $uri = $parser->parse('http://example.com'); - $this->config->set('URI', 'DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation'); + $this->config->set('URI.DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation'); generate_mock_once('HTMLPurifier_URIDefinition'); $uri_def = new HTMLPurifier_URIDefinitionMock(); @@ -121,8 +121,8 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness /* function test_validate_configWhitelist() { - $this->config->set('URI', 'HostPolicy', 'DenyAll'); - $this->config->set('URI', 'HostWhitelist', array(null, 'google.com')); + $this->config->set('URI.HostPolicy', 'DenyAll'); + $this->config->set('URI.HostWhitelist', array(null, 'google.com')); $this->assertDef('http://example.com/fo/google.com', false); $this->assertDef('server.txt'); diff --git a/tests/HTMLPurifier/AttrTransform/BdoDirTest.php b/tests/HTMLPurifier/AttrTransform/BdoDirTest.php index c8237898..cdf6f8a9 100644 --- a/tests/HTMLPurifier/AttrTransform/BdoDirTest.php +++ b/tests/HTMLPurifier/AttrTransform/BdoDirTest.php @@ -17,7 +17,7 @@ class HTMLPurifier_AttrTransform_BdoDirTest extends HTMLPurifier_AttrTransformHa } function testAlternateDefault() { - $this->config->set('Attr', 'DefaultTextDir', 'rtl'); + $this->config->set('Attr.DefaultTextDir', 'rtl'); $this->assertResult( array(), array('dir' => 'rtl') diff --git a/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php b/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php index d22a2763..99f0a03e 100644 --- a/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php +++ b/tests/HTMLPurifier/AttrTransform/ImgRequiredTest.php @@ -9,7 +9,7 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf } function testAddMissingAttr() { - $this->config->set('Core', 'RemoveInvalidImg', false); + $this->config->set('Core.RemoveInvalidImg', false); $this->assertResult( array(), array('src' => '', 'alt' => 'Invalid image') @@ -17,10 +17,10 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf } function testAlternateDefaults() { - $this->config->set('Attr', 'DefaultInvalidImage', 'blank.png'); - $this->config->set('Attr', 'DefaultInvalidImageAlt', 'Pawned!'); - $this->config->set('Attr', 'DefaultImageAlt', 'not pawned'); - $this->config->set('Core', 'RemoveInvalidImg', false); + $this->config->set('Attr.DefaultInvalidImage', 'blank.png'); + $this->config->set('Attr.DefaultInvalidImageAlt', 'Pawned!'); + $this->config->set('Attr.DefaultImageAlt', 'not pawned'); + $this->config->set('Core.RemoveInvalidImg', false); $this->assertResult( array(), array('src' => 'blank.png', 'alt' => 'Pawned!') @@ -35,7 +35,7 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf } function testAddDefaultSrc() { - $this->config->set('Core', 'RemoveInvalidImg', false); + $this->config->set('Core.RemoveInvalidImg', false); $this->assertResult( array('alt' => 'intrigue'), array('alt' => 'intrigue', 'src' => '') @@ -43,7 +43,7 @@ class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransf } function testAddDefaultAlt() { - $this->config->set('Attr', 'DefaultImageAlt', 'default'); + $this->config->set('Attr.DefaultImageAlt', 'default'); $this->assertResult( array('src' => ''), array('src' => '', 'alt' => 'default') diff --git a/tests/HTMLPurifier/AttrValidator_ErrorsTest.php b/tests/HTMLPurifier/AttrValidator_ErrorsTest.php index cdc27414..eca491df 100644 --- a/tests/HTMLPurifier/AttrValidator_ErrorsTest.php +++ b/tests/HTMLPurifier/AttrValidator_ErrorsTest.php @@ -18,7 +18,7 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness } function testAttributesTransformedGlobalPre() { - $this->config->set('HTML', 'DefinitionID', + $this->config->set('HTML.DefinitionID', 'HTMLPurifier_AttrValidator_ErrorsTest::testAttributesTransformedGlobalPre'); $def = $this->config->getHTMLDefinition(true); generate_mock_once('HTMLPurifier_AttrTransform'); @@ -39,7 +39,7 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness } function testAttributesTransformedLocalPre() { - $this->config->set('HTML', 'TidyLevel', 'heavy'); + $this->config->set('HTML.TidyLevel', 'heavy'); $input = array('align' => 'right'); $output = array('style' => 'text-align:right;'); $token = new HTMLPurifier_Token_Start('p', $input, 1); diff --git a/tests/HTMLPurifier/ChildDef/RequiredTest.php b/tests/HTMLPurifier/ChildDef/RequiredTest.php index f8d23075..8bb4f45e 100644 --- a/tests/HTMLPurifier/ChildDef/RequiredTest.php +++ b/tests/HTMLPurifier/ChildDef/RequiredTest.php @@ -62,7 +62,7 @@ class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness function testPCDATAAllowedWithEscaping() { $this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b'); - $this->config->set('Core', 'EscapeInvalidChildren', true); + $this->config->set('Core.EscapeInvalidChildren', true); $this->assertResult( 'Out Bold text', 'Out Bold text<img />' diff --git a/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php b/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php index 61fe1a2a..52594b1a 100644 --- a/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php +++ b/tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php @@ -65,7 +65,7 @@ extends HTMLPurifier_ChildDefHarness } function testAlternateWrapper() { - $this->config->set('HTML', 'BlockWrapper', 'div'); + $this->config->set('HTML.BlockWrapper', 'div'); $this->assertResult('Needs wrap', '

Needs wrap
'); } @@ -73,8 +73,8 @@ extends HTMLPurifier_ChildDefHarness function testError() { $this->expectError('Cannot use non-block element as block wrapper'); $this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p'); - $this->config->set('HTML', 'BlockWrapper', 'dav'); - $this->config->set('Cache', 'DefinitionImpl', null); + $this->config->set('HTML.BlockWrapper', 'dav'); + $this->config->set('Cache.DefinitionImpl', null); $this->assertResult('Needs wrap', '

Needs wrap

'); } diff --git a/tests/HTMLPurifier/ChildDef/TableTest.php b/tests/HTMLPurifier/ChildDef/TableTest.php index 95408671..034e025b 100644 --- a/tests/HTMLPurifier/ChildDef/TableTest.php +++ b/tests/HTMLPurifier/ChildDef/TableTest.php @@ -43,12 +43,12 @@ class HTMLPurifier_ChildDef_TableTest extends HTMLPurifier_ChildDefHarness } function testStickyWhitespaceOnTr() { - $this->config->set('Output', 'Newline', "\n"); + $this->config->set('Output.Newline', "\n"); $this->assertResult("\n \n \n "); } function testStickyWhitespaceOnTSection() { - $this->config->set('Output', 'Newline', "\n"); + $this->config->set('Output.Newline', "\n"); $this->assertResult( "\n\t\n\t\t\n\t\t\t", "\n\t\t\n\t\n\t\t\t" diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php index 6cc862cf..02ea80d8 100644 --- a/tests/HTMLPurifier/ConfigTest.php +++ b/tests/HTMLPurifier/ConfigTest.php @@ -25,48 +25,49 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $config = new HTMLPurifier_Config($this->schema); $config->autoFinalize = false; + $config->chatty = false; // test default value retrieval - $this->assertIdentical($config->get('Element', 'Abbr'), 'H'); - $this->assertIdentical($config->get('Element', 'Name'), 'hydrogen'); - $this->assertIdentical($config->get('Element', 'Number'), 1); - $this->assertIdentical($config->get('Element', 'Mass'), 1.00794); - $this->assertIdentical($config->get('Element', 'Radioactive'), false); - $this->assertIdentical($config->get('Element', 'Isotopes'), array(1 => true, 2 => true, 3 => true)); - $this->assertIdentical($config->get('Element', 'Traits'), array('nonmetallic', 'odorless', 'flammable')); - $this->assertIdentical($config->get('Element', 'IsotopeNames'), array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium')); - $this->assertIdentical($config->get('Element', 'Object'), new stdClass()); + $this->assertIdentical($config->get('Element.Abbr'), 'H'); + $this->assertIdentical($config->get('Element.Name'), 'hydrogen'); + $this->assertIdentical($config->get('Element.Number'), 1); + $this->assertIdentical($config->get('Element.Mass'), 1.00794); + $this->assertIdentical($config->get('Element.Radioactive'), false); + $this->assertIdentical($config->get('Element.Isotopes'), array(1 => true, 2 => true, 3 => true)); + $this->assertIdentical($config->get('Element.Traits'), array('nonmetallic', 'odorless', 'flammable')); + $this->assertIdentical($config->get('Element.IsotopeNames'), array(1 => 'protium', 2 => 'deuterium', 3 => 'tritium')); + $this->assertIdentical($config->get('Element.Object'), new stdClass()); // test setting values - $config->set('Element', 'Abbr', 'Pu'); - $config->set('Element', 'Name', 'PLUTONIUM'); // test decaps - $config->set('Element', 'Number', '94'); // test parsing - $config->set('Element', 'Mass', '244.'); // test parsing - $config->set('Element', 'Radioactive', true); - $config->set('Element', 'Isotopes', array(238, 239)); // test inversion - $config->set('Element', 'Traits', 'nuclear, heavy, actinide'); // test parsing - $config->set('Element', 'IsotopeNames', array(238 => 'Plutonium-238', 239 => 'Plutonium-239')); - $config->set('Element', 'Object', false); // unmodeled + $config->set('Element.Abbr', 'Pu'); + $config->set('Element.Name', 'PLUTONIUM'); // test decaps + $config->set('Element.Number', '94'); // test parsing + $config->set('Element.Mass', '244.'); // test parsing + $config->set('Element.Radioactive', true); + $config->set('Element.Isotopes', array(238, 239)); // test inversion + $config->set('Element.Traits', 'nuclear, heavy, actinide'); // test parsing + $config->set('Element.IsotopeNames', array(238 => 'Plutonium-238', 239 => 'Plutonium-239')); + $config->set('Element.Object', false); // unmodeled $this->expectError('Cannot set undefined directive Element.Metal to value'); - $config->set('Element', 'Metal', true); + $config->set('Element.Metal', true); $this->expectError('Value for Element.Radioactive is of invalid type, should be bool'); - $config->set('Element', 'Radioactive', 'very'); + $config->set('Element.Radioactive', 'very'); // test value retrieval - $this->assertIdentical($config->get('Element', 'Abbr'), 'Pu'); - $this->assertIdentical($config->get('Element', 'Name'), 'plutonium'); - $this->assertIdentical($config->get('Element', 'Number'), 94); - $this->assertIdentical($config->get('Element', 'Mass'), 244.); - $this->assertIdentical($config->get('Element', 'Radioactive'), true); - $this->assertIdentical($config->get('Element', 'Isotopes'), array(238 => true, 239 => true)); - $this->assertIdentical($config->get('Element', 'Traits'), array('nuclear', 'heavy', 'actinide')); - $this->assertIdentical($config->get('Element', 'IsotopeNames'), array(238 => 'Plutonium-238', 239 => 'Plutonium-239')); - $this->assertIdentical($config->get('Element', 'Object'), false); + $this->assertIdentical($config->get('Element.Abbr'), 'Pu'); + $this->assertIdentical($config->get('Element.Name'), 'plutonium'); + $this->assertIdentical($config->get('Element.Number'), 94); + $this->assertIdentical($config->get('Element.Mass'), 244.); + $this->assertIdentical($config->get('Element.Radioactive'), true); + $this->assertIdentical($config->get('Element.Isotopes'), array(238 => true, 239 => true)); + $this->assertIdentical($config->get('Element.Traits'), array('nuclear', 'heavy', 'actinide')); + $this->assertIdentical($config->get('Element.IsotopeNames'), array(238 => 'Plutonium-238', 239 => 'Plutonium-239')); + $this->assertIdentical($config->get('Element.Object'), false); $this->expectError('Cannot retrieve value of undefined directive Element.Metal'); - $config->get('Element', 'Metal'); + $config->get('Element.Metal'); } @@ -90,31 +91,32 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $config = new HTMLPurifier_Config($this->schema); $config->autoFinalize = false; + $config->chatty = false; // case sensitive - $config->set('Instrument', 'Manufacturer', 'Vandoren'); - $this->assertIdentical($config->get('Instrument', 'Manufacturer'), 'Vandoren'); + $config->set('Instrument.Manufacturer', 'Vandoren'); + $this->assertIdentical($config->get('Instrument.Manufacturer'), 'Vandoren'); - $config->set('Instrument', 'Manufacturer', 'Selmer'); - $this->assertIdentical($config->get('Instrument', 'Manufacturer'), 'Conn-Selmer'); + $config->set('Instrument.Manufacturer', 'Selmer'); + $this->assertIdentical($config->get('Instrument.Manufacturer'), 'Conn-Selmer'); $this->expectError('Value not supported, valid values are: Yamaha, Conn-Selmer, Vandoren, Laubin, Buffet, other'); - $config->set('Instrument', 'Manufacturer', 'buffet'); + $config->set('Instrument.Manufacturer', 'buffet'); // case insensitive - $config->set('Instrument', 'Family', 'brass'); - $this->assertIdentical($config->get('Instrument', 'Family'), 'brass'); + $config->set('Instrument.Family', 'brass'); + $this->assertIdentical($config->get('Instrument.Family'), 'brass'); - $config->set('Instrument', 'Family', 'PERCUSSION'); - $this->assertIdentical($config->get('Instrument', 'Family'), 'percussion'); + $config->set('Instrument.Family', 'PERCUSSION'); + $this->assertIdentical($config->get('Instrument.Family'), 'percussion'); - $config->set('Instrument', 'Family', 'synth'); - $this->assertIdentical($config->get('Instrument', 'Family'), 'electronic'); + $config->set('Instrument.Family', 'synth'); + $this->assertIdentical($config->get('Instrument.Family'), 'electronic'); - $config->set('Instrument', 'Family', 'Synth'); - $this->assertIdentical($config->get('Instrument', 'Family'), 'electronic'); + $config->set('Instrument.Family', 'Synth'); + $this->assertIdentical($config->get('Instrument.Family'), 'electronic'); } @@ -125,16 +127,17 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $config = new HTMLPurifier_Config($this->schema); $config->autoFinalize = false; + $config->chatty = false; - $config->set('ReportCard', 'English', 'B-'); - $this->assertIdentical($config->get('ReportCard', 'English'), 'B-'); + $config->set('ReportCard.English', 'B-'); + $this->assertIdentical($config->get('ReportCard.English'), 'B-'); - $config->set('ReportCard', 'English', null); // not yet graded - $this->assertIdentical($config->get('ReportCard', 'English'), null); + $config->set('ReportCard.English', null); // not yet graded + $this->assertIdentical($config->get('ReportCard.English'), null); // error $this->expectError('Value for ReportCard.Absences is of invalid type, should be int'); - $config->set('ReportCard', 'Absences', null); + $config->set('ReportCard.Absences', null); } @@ -145,15 +148,16 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $config = new HTMLPurifier_Config($this->schema); $config->autoFinalize = false; + $config->chatty = false; - $this->assertIdentical($config->get('Home', 'Rug'), 3); + $this->assertIdentical($config->get('Home.Rug'), 3); $this->expectError('Cannot get value from aliased directive, use real name Home.Rug'); - $config->get('Home', 'Carpet'); + $config->get('Home.Carpet'); $this->expectError('Home.Carpet is an alias, preferred directive name is Home.Rug'); - $config->set('Home', 'Carpet', 999); - $this->assertIdentical($config->get('Home', 'Rug'), 999); + $config->set('Home.Carpet', 999); + $this->assertIdentical($config->get('Home.Rug'), 999); } @@ -166,6 +170,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $config = new HTMLPurifier_Config($this->schema); $config->autoFinalize = false; + $config->chatty = false; // grab a namespace $this->assertIdentical( @@ -193,9 +198,9 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $config->loadIni(dirname(__FILE__) . '/ConfigTest-loadIni.ini'); - $this->assertIdentical($config->get('Shortcut', 'Copy'), 'q'); - $this->assertIdentical($config->get('Shortcut', 'Paste'), 'p'); - $this->assertIdentical($config->get('Shortcut', 'Cut'), 't'); + $this->assertIdentical($config->get('Shortcut.Copy'), 'q'); + $this->assertIdentical($config->get('Shortcut.Paste'), 'p'); + $this->assertIdentical($config->get('Shortcut.Cut'), 't'); } @@ -205,7 +210,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness // generation routines have dependencies on configuration values $config = HTMLPurifier_Config::createDefault(); - $config->set('HTML', 'Doctype', 'XHTML 1.0 Strict'); + $config->set('HTML.Doctype', 'XHTML 1.0 Strict'); $config->autoFinalize = false; $def = $config->getCSSDefinition(); @@ -219,15 +224,15 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $old_def = clone $def2; - $config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); + $config->set('HTML.Doctype', 'HTML 4.01 Transitional'); $def = $config->getHTMLDefinition(); $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition'); $this->assertNotEqual($def, $old_def); $this->assertTrue($def->setup); // test retrieval of raw definition - $config->set('HTML', 'DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()'); - $config->set('HTML', 'DefinitionRev', 3); + $config->set('HTML.DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()'); + $config->set('HTML.DefinitionRev', 3); $def = $config->getHTMLDefinition(true); $this->assertNotEqual($def, $old_def); $this->assertEqual(false, $def->setup); @@ -268,10 +273,10 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $config_loadabbr = new HTMLPurifier_Config($this->schema); $config_loadfull = new HTMLPurifier_Config($this->schema); - $config_manual->set('Zoo', 'Aadvark', 3); - $config_manual->set('Zoo', 'Boar', 5); - $config_manual->set('Zoo', 'Camel', 2000); // that's a lotta camels! - $config_manual->set('Zoo', 'Others', array('Peacock', 'Dodo')); // wtf! + $config_manual->set('Zoo.Aadvark', 3); + $config_manual->set('Zoo.Boar', 5); + $config_manual->set('Zoo.Camel', 2000); // that's a lotta camels! + $config_manual->set('Zoo.Others', array('Peacock', 'Dodo')); // wtf! // condensed form $config_loadabbr->loadArray(array( @@ -302,7 +307,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $this->schema->add('Cake.Flavor', 'vanilla', 'string', false); $config = new HTMLPurifier_Config($this->schema); - $config->set('Cake', 'Sprinkles', 42); + $config->set('Cake.Sprinkles', 42); // test flat pass-through $created_config = HTMLPurifier_Config::create($config, $this->schema); @@ -326,13 +331,14 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $config = new HTMLPurifier_Config($this->schema); $config->autoFinalize = false; + $config->chatty = false; - $config->set('Poem', 'Meter', 'irregular'); + $config->set('Poem.Meter', 'irregular'); $config->finalize(); $this->expectError('Cannot set directive after finalization'); - $config->set('Poem', 'Meter', 'vedic'); + $config->set('Poem.Meter', 'vedic'); $this->expectError('Cannot load directives after finalization'); $config->loadArray(array('Poem.Meter' => 'octosyllable')); @@ -422,6 +428,15 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness } + function testDeprecatedAPI() { + $this->schema->add('Foo.Bar', 2, 'int', false); + $config = new HTMLPurifier_Config($this->schema); + $config->chatty = false; + $this->expectError('Using deprecated API: use $config->set(\'Foo.Bar\', ...) instead'); + $config->set('Foo', 'Bar', 4); + $this->expectError('Using deprecated API: use $config->get(\'Foo.Bar\') instead'); + $this->assertIdentical($config->get('Foo', 'Bar'), 4); + } } // vim: et sw=4 sts=4 diff --git a/tests/HTMLPurifier/DefinitionCache/SerializerTest.php b/tests/HTMLPurifier/DefinitionCache/SerializerTest.php index 5791bbdf..149fd38e 100644 --- a/tests/HTMLPurifier/DefinitionCache/SerializerTest.php +++ b/tests/HTMLPurifier/DefinitionCache/SerializerTest.php @@ -8,7 +8,7 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio $cache = new HTMLPurifier_DefinitionCache_Serializer('Test'); $config = $this->generateConfigMock('serial'); - $config->setReturnValue('get', 2, array('Test', 'DefinitionRev')); + $config->setReturnValue('get', 2, array('Test.DefinitionRev')); $config->version = '1.0.0'; $config_md5 = '1.0.0,serial,2'; @@ -116,12 +116,12 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio $config1 = $this->generateConfigMock(); $config1->version = '0.9.0'; - $config1->setReturnValue('get', 574, array('Test', 'DefinitionRev')); + $config1->setReturnValue('get', 574, array('Test.DefinitionRev')); $def1 = $this->generateDefinition(array('info' => 1)); $config2 = $this->generateConfigMock(); $config2->version = '1.0.0beta'; - $config2->setReturnValue('get', 1, array('Test', 'DefinitionRev')); + $config2->setReturnValue('get', 1, array('Test.DefinitionRev')); $def2 = $this->generateDefinition(array('info' => 3)); $cache->set($def1, $config1); @@ -140,12 +140,12 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio $config1 = $this->generateConfigMock('serial1'); $config1->version = '1.0.0'; - $config1->setReturnValue('get', 1, array('Test', 'DefinitionRev')); + $config1->setReturnValue('get', 1, array('Test.DefinitionRev')); $def1 = $this->generateDefinition(array('info' => 1)); $config2 = $this->generateConfigMock('serial2'); $config2->version = '1.0.0'; - $config2->setReturnValue('get', 34, array('Test', 'DefinitionRev')); + $config2->setReturnValue('get', 34, array('Test.DefinitionRev')); $def2 = $this->generateDefinition(array('info' => 3)); $cache->set($def1, $config1); @@ -180,9 +180,9 @@ class HTMLPurifier_DefinitionCache_SerializerTest extends HTMLPurifier_Definitio $cache = new HTMLPurifier_DefinitionCache_Serializer('Test'); $config = $this->generateConfigMock('serial'); $config->version = '1.0.0'; - $config->setReturnValue('get', 1, array('Test', 'DefinitionRev')); + $config->setReturnValue('get', 1, array('Test.DefinitionRev')); $dir = dirname(__FILE__) . '/SerializerTest'; - $config->setReturnValue('get', $dir, array('Cache', 'SerializerPath')); + $config->setReturnValue('get', $dir, array('Cache.SerializerPath')); $def_original = $this->generateDefinition(); $cache->add($def_original, $config); diff --git a/tests/HTMLPurifier/DefinitionCacheFactoryTest.php b/tests/HTMLPurifier/DefinitionCacheFactoryTest.php index 8ad7ec6f..d50ef8be 100644 --- a/tests/HTMLPurifier/DefinitionCacheFactoryTest.php +++ b/tests/HTMLPurifier/DefinitionCacheFactoryTest.php @@ -45,21 +45,21 @@ class HTMLPurifier_DefinitionCacheFactoryTest extends HTMLPurifier_Harness } function test_create_invalid() { - $this->config->set('Cache', 'DefinitionImpl', 'Invalid'); + $this->config->set('Cache.DefinitionImpl', 'Invalid'); $this->expectError('Unrecognized DefinitionCache Invalid, using Serializer instead'); $cache = $this->factory->create('Test', $this->config); $this->assertIsA($cache, 'HTMLPurifier_DefinitionCache_Serializer'); } function test_null() { - $this->config->set('Cache', 'DefinitionImpl', null); + $this->config->set('Cache.DefinitionImpl', null); $cache = $this->factory->create('Test', $this->config); $this->assertEqual($cache, new HTMLPurifier_DefinitionCache_Null('Test')); } function test_register() { generate_mock_once('HTMLPurifier_DefinitionCache'); - $this->config->set('Cache', 'DefinitionImpl', 'TestCache'); + $this->config->set('Cache.DefinitionImpl', 'TestCache'); $this->factory->register('TestCache', $class = 'HTMLPurifier_DefinitionCacheMock'); $cache = $this->factory->create('Test', $this->config); $this->assertIsA($cache, $class); diff --git a/tests/HTMLPurifier/DefinitionCacheTest.php b/tests/HTMLPurifier/DefinitionCacheTest.php index 247d1349..5ad2ff9c 100644 --- a/tests/HTMLPurifier/DefinitionCacheTest.php +++ b/tests/HTMLPurifier/DefinitionCacheTest.php @@ -10,7 +10,7 @@ class HTMLPurifier_DefinitionCacheTest extends HTMLPurifier_Harness generate_mock_once('HTMLPurifier_Config'); $config = new HTMLPurifier_ConfigMock(); $config->version = '1.0.0'; // hopefully no conflicts - $config->setReturnValue('get', 10, array('Test', 'DefinitionRev')); + $config->setReturnValue('get', 10, array('Test.DefinitionRev')); $config->setReturnValue('getBatchSerial', 'hash', array('Test')); $this->assertIdentical($cache->isOld('1.0.0,hash,10', $config), false); diff --git a/tests/HTMLPurifier/EncoderTest.php b/tests/HTMLPurifier/EncoderTest.php index 8aba3bda..89ff4f38 100644 --- a/tests/HTMLPurifier/EncoderTest.php +++ b/tests/HTMLPurifier/EncoderTest.php @@ -39,7 +39,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness } function test_convertToUTF8_spuriousEncoding() { - $this->config->set('Core', 'Encoding', 'utf99'); + $this->config->set('Core.Encoding', 'utf99'); $this->expectError('Invalid encoding utf99'); $this->assertIdentical( HTMLPurifier_Encoder::convertToUTF8("\xF6", $this->config, $this->context), @@ -48,7 +48,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness } function test_convertToUTF8_iso8859_1() { - $this->config->set('Core', 'Encoding', 'ISO-8859-1'); + $this->config->set('Core.Encoding', 'ISO-8859-1'); $this->assertIdentical( HTMLPurifier_Encoder::convertToUTF8("\xF6", $this->config, $this->context), "\xC3\xB6" @@ -56,8 +56,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness } function test_convertToUTF8_withoutIconv() { - $this->config->set('Core', 'Encoding', 'ISO-8859-1'); - $this->config->set('Test', 'ForceNoIconv', true); + $this->config->set('Core.Encoding', 'ISO-8859-1'); + $this->config->set('Test.ForceNoIconv', true); $this->assertIdentical( HTMLPurifier_Encoder::convertToUTF8("\xF6", $this->config, $this->context), "\xC3\xB6" @@ -78,7 +78,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness } function test_convertFromUTF8_iso8859_1() { - $this->config->set('Core', 'Encoding', 'ISO-8859-1'); + $this->config->set('Core.Encoding', 'ISO-8859-1'); $this->assertIdentical( HTMLPurifier_Encoder::convertFromUTF8("\xC3\xB6", $this->config, $this->context), "\xF6", @@ -88,7 +88,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness function test_convertFromUTF8_iconvNoChars() { if (!function_exists('iconv')) return; - $this->config->set('Core', 'Encoding', 'ISO-8859-1'); + $this->config->set('Core.Encoding', 'ISO-8859-1'); $this->assertIdentical( HTMLPurifier_Encoder::convertFromUTF8($this->getZhongWen(), $this->config, $this->context), " (Chinese)" @@ -97,8 +97,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness function test_convertFromUTF8_phpNormal() { // Plain PHP implementation has slightly different behavior - $this->config->set('Core', 'Encoding', 'ISO-8859-1'); - $this->config->set('Test', 'ForceNoIconv', true); + $this->config->set('Core.Encoding', 'ISO-8859-1'); + $this->config->set('Test.ForceNoIconv', true); $this->assertIdentical( HTMLPurifier_Encoder::convertFromUTF8("\xC3\xB6", $this->config, $this->context), "\xF6", @@ -107,8 +107,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness } function test_convertFromUTF8_phpNoChars() { - $this->config->set('Core', 'Encoding', 'ISO-8859-1'); - $this->config->set('Test', 'ForceNoIconv', true); + $this->config->set('Core.Encoding', 'ISO-8859-1'); + $this->config->set('Test.ForceNoIconv', true); $this->assertIdentical( HTMLPurifier_Encoder::convertFromUTF8($this->getZhongWen(), $this->config, $this->context), "?? (Chinese)" @@ -117,8 +117,8 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness function test_convertFromUTF8_withProtection() { // Preserve the characters! - $this->config->set('Core', 'Encoding', 'ISO-8859-1'); - $this->config->set('Core', 'EscapeNonASCIICharacters', true); + $this->config->set('Core.Encoding', 'ISO-8859-1'); + $this->config->set('Core.EscapeNonASCIICharacters', true); $this->assertIdentical( HTMLPurifier_Encoder::convertFromUTF8($this->getZhongWen(), $this->config, $this->context), "中文 (Chinese)" @@ -169,7 +169,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness function testShiftJIS() { if (!function_exists('iconv')) return; - $this->config->set('Core', 'Encoding', 'Shift_JIS'); + $this->config->set('Core.Encoding', 'Shift_JIS'); // This actually looks like a Yen, but we're going to treat it differently $this->assertIdentical( HTMLPurifier_Encoder::convertFromUTF8('\\~', $this->config, $this->context), diff --git a/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php b/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php index 48672b47..51499c60 100644 --- a/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php +++ b/tests/HTMLPurifier/Filter/ExtractStyleBlocksTest.php @@ -8,7 +8,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness // usual use case: function test_tokenizeHTML_extractStyleBlocks() { - $this->config->set('Filter', 'ExtractStyleBlocks', true); + $this->config->set('Filter.ExtractStyleBlocks', true); $purifier = new HTMLPurifier($this->config); $result = $purifier->purify('Test'); $this->assertIdentical($result, 'Test'); @@ -23,7 +23,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness function assertExtractStyleBlocks($html, $expect = true, $styles = array()) { $filter = new HTMLPurifier_Filter_ExtractStyleBlocks(); // disable cleaning if ($expect === true) $expect = $html; - $this->config->set('FilterParam', 'ExtractStyleBlocksTidyImpl', false); + $this->config->set('FilterParam.ExtractStyleBlocksTidyImpl', false); $result = $filter->preFilter($html, $this->config, $this->context); $this->assertIdentical($result, $expect); $this->assertIdentical($this->context->get('StyleBlocks'), $styles); @@ -104,14 +104,14 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness } function test_cleanCSS_noEscapeCodes() { - $this->config->set('FilterParam', 'ExtractStyleBlocksEscaping', false); + $this->config->set('FilterParam.ExtractStyleBlocksEscaping', false); $this->assertCleanCSS( ".class {\nfont-family:'';\n}" ); } function test_cleanCSS_scope() { - $this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo'); + $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo'); $this->assertCleanCSS( "p {\ntext-indent:1em;\n}", "#foo p {\ntext-indent:1em;\n}" @@ -119,7 +119,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness } function test_cleanCSS_scopeWithSelectorCommas() { - $this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo'); + $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo'); $this->assertCleanCSS( "b, i {\ntext-decoration:underline;\n}", "#foo b, #foo i {\ntext-decoration:underline;\n}" @@ -127,17 +127,17 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness } function test_cleanCSS_scopeWithNaughtySelector() { - $this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo'); + $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo'); $this->assertCleanCSS(" + p {\ntext-indent:1em;\n}", ''); } function test_cleanCSS_scopeWithMultipleNaughtySelectors() { - $this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo'); + $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo'); $this->assertCleanCSS(" ++ ++ p {\ntext-indent:1em;\n}", ''); } function test_cleanCSS_scopeWithCommas() { - $this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo, .bar'); + $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo, .bar'); $this->assertCleanCSS( "p {\ntext-indent:1em;\n}", "#foo p, .bar p {\ntext-indent:1em;\n}" @@ -145,7 +145,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness } function test_cleanCSS_scopeAllWithCommas() { - $this->config->set('FilterParam', 'ExtractStyleBlocksScope', '#foo, .bar'); + $this->config->set('FilterParam.ExtractStyleBlocksScope', '#foo, .bar'); $this->assertCleanCSS( "p, div {\ntext-indent:1em;\n}", "#foo p, #foo div, .bar p, .bar div {\ntext-indent:1em;\n}" @@ -153,7 +153,7 @@ class HTMLPurifier_Filter_ExtractStyleBlocksTest extends HTMLPurifier_Harness } function test_cleanCSS_scopeWithConflicts() { - $this->config->set('FilterParam', 'ExtractStyleBlocksScope', 'p'); + $this->config->set('FilterParam.ExtractStyleBlocksScope', 'p'); $this->assertCleanCSS( "div { text-align:right; diff --git a/tests/HTMLPurifier/GeneratorTest.php b/tests/HTMLPurifier/GeneratorTest.php index a9379324..67016e40 100644 --- a/tests/HTMLPurifier/GeneratorTest.php +++ b/tests/HTMLPurifier/GeneratorTest.php @@ -15,7 +15,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness public function setUp() { parent::setUp(); - $this->config->set('Output', 'Newline', "\n"); + $this->config->set('Output.Newline', "\n"); } /** @@ -138,7 +138,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness function test_generateAttributes_minimized() { - $this->config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); + $this->config->set('HTML.Doctype', 'HTML 4.01 Transitional'); $this->assertGenerateAttributes( array('compact' => 'compact'), 'compact', 'menu' ); @@ -197,7 +197,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness } function test_generateFromTokens_Scripting_disableWrapper() { - $this->config->set('Output', 'CommentScriptContents', false); + $this->config->set('Output.CommentScriptContents', false); $this->assertGeneration( array( new HTMLPurifier_Token_Start('script'), @@ -209,7 +209,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness } function test_generateFromTokens_XHTMLoff() { - $this->config->set('HTML', 'XHTML', false); + $this->config->set('HTML.XHTML', false); // omit trailing slash $this->assertGeneration( @@ -236,8 +236,8 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness // just don't test; Tidy is exploding on me. return; - $this->config->set('Core', 'TidyFormat', true); - $this->config->set('Output', 'Newline', "\n"); + $this->config->set('Core.TidyFormat', true); + $this->config->set('Output.Newline', "\n"); // nice wrapping please $this->assertGeneration( @@ -252,7 +252,7 @@ class HTMLPurifier_GeneratorTest extends HTMLPurifier_Harness } function test_generateFromTokens_sortAttr() { - $this->config->set('Output', 'SortAttr', true); + $this->config->set('Output.SortAttr', true); $this->assertGeneration( array( new HTMLPurifier_Token_Start('p', array('b'=>'c', 'a'=>'d')) ), diff --git a/tests/HTMLPurifier/HTMLDefinitionTest.php b/tests/HTMLPurifier/HTMLDefinitionTest.php index 389a4b94..e7f85011 100644 --- a/tests/HTMLPurifier/HTMLDefinitionTest.php +++ b/tests/HTMLPurifier/HTMLDefinitionTest.php @@ -6,7 +6,7 @@ class HTMLPurifier_HTMLDefinitionTest extends HTMLPurifier_Harness function expectError($error = false, $message = '%s') { // Because we're testing a definition, it's vital that the cache // is turned off for tests that expect errors. - $this->config->set('Cache', 'DefinitionImpl', null); + $this->config->set('Cache.DefinitionImpl', null); parent::expectError($error); } @@ -87,29 +87,29 @@ a[href|title] } function test_AllowedElements() { - $this->config->set('HTML', 'AllowedElements', 'p'); + $this->config->set('HTML.AllowedElements', 'p'); $this->assertPurification_AllowedElements_p(); } function test_AllowedElements_multiple() { - $this->config->set('HTML', 'AllowedElements', 'p,div'); + $this->config->set('HTML.AllowedElements', 'p,div'); $this->assertPurification('

Jelly

', '

Jelly

'); } function test_AllowedElements_invalidElement() { - $this->config->set('HTML', 'AllowedElements', 'obviously_invalid,p'); + $this->config->set('HTML.AllowedElements', 'obviously_invalid,p'); $this->expectError(new PatternExpectation("/Element 'obviously_invalid' is not supported/")); $this->assertPurification_AllowedElements_p(); } function test_AllowedElements_invalidElement_xssAttempt() { - $this->config->set('HTML', 'AllowedElements', '', '' ); diff --git a/tests/HTMLPurifier/HTMLModuleManagerTest.php b/tests/HTMLPurifier/HTMLModuleManagerTest.php index 32ddab5e..2750f892 100644 --- a/tests/HTMLPurifier/HTMLModuleManagerTest.php +++ b/tests/HTMLPurifier/HTMLModuleManagerTest.php @@ -6,7 +6,7 @@ class HTMLPurifier_HTMLModuleManagerTest extends HTMLPurifier_Harness protected function createManager() { $manager = new HTMLPurifier_HTMLModuleManager(); - $this->config->set('HTML', 'CustomDoctype', 'Blank'); + $this->config->set('HTML.CustomDoctype', 'Blank'); $manager->doctypes->register('Blank'); $attrdef_nmtokens = new HTMLPurifier_AttrDef_HTML_Nmtokens(); @@ -47,8 +47,8 @@ class HTMLPurifier_HTMLModuleManagerTest extends HTMLPurifier_Harness $manager->addModule($unsafe_module); $config = HTMLPurifier_Config::createDefault(); - $config->set('HTML', 'Trusted', false); - $config->set('HTML', 'CustomDoctype', 'Blank'); + $config->set('HTML.Trusted', false); + $config->set('HTML.CustomDoctype', 'Blank'); $manager->setup($config); diff --git a/tests/HTMLPurifier/HTMLT.php b/tests/HTMLPurifier/HTMLT.php index b32a072e..06e7958f 100644 --- a/tests/HTMLPurifier/HTMLT.php +++ b/tests/HTMLPurifier/HTMLT.php @@ -15,7 +15,7 @@ class HTMLPurifier_HTMLT extends HTMLPurifier_Harness if (isset($hash['SKIPIF'])) { if (eval($hash['SKIPIF'])) return; } - $this->config->set('Output', 'Newline', "\n"); + $this->config->set('Output.Newline', "\n"); if (isset($hash['INI'])) { // there should be a more efficient way than writing another // ini file every time... probably means building a parser for diff --git a/tests/HTMLPurifier/Harness.php b/tests/HTMLPurifier/Harness.php index fc484bfd..d6490a11 100644 --- a/tests/HTMLPurifier/Harness.php +++ b/tests/HTMLPurifier/Harness.php @@ -18,7 +18,7 @@ class HTMLPurifier_Harness extends UnitTestCase */ public function setUp() { list($this->config, $this->context) = $this->createCommon(); - $this->config->set('Output', 'Newline', ' + $this->config->set('Output.Newline', ' '); $this->purifier = new HTMLPurifier(); } diff --git a/tests/HTMLPurifier/IDAccumulatorTest.php b/tests/HTMLPurifier/IDAccumulatorTest.php index c748845f..90bca073 100644 --- a/tests/HTMLPurifier/IDAccumulatorTest.php +++ b/tests/HTMLPurifier/IDAccumulatorTest.php @@ -29,7 +29,7 @@ class HTMLPurifier_IDAccumulatorTest extends HTMLPurifier_Harness } function testBuild() { - $this->config->set('Attr', 'IDBlacklist', array('foo')); + $this->config->set('Attr.IDBlacklist', array('foo')); $accumulator = HTMLPurifier_IDAccumulator::build($this->config, $this->context); $this->assertTrue( isset($accumulator->ids['foo']) ); } diff --git a/tests/HTMLPurifier/Injector/AutoParagraphTest.php b/tests/HTMLPurifier/Injector/AutoParagraphTest.php index b5fc0325..22083cbf 100644 --- a/tests/HTMLPurifier/Injector/AutoParagraphTest.php +++ b/tests/HTMLPurifier/Injector/AutoParagraphTest.php @@ -5,7 +5,7 @@ class HTMLPurifier_Injector_AutoParagraphTest extends HTMLPurifier_InjectorHarne function setup() { parent::setup(); - $this->config->set('AutoFormat', 'AutoParagraph', true); + $this->config->set('AutoFormat.AutoParagraph', true); } function testSingleParagraph() { @@ -385,7 +385,7 @@ Par1 } function testNoParagraphWithInlineRootNode() { - $this->config->set('HTML', 'Parent', 'span'); + $this->config->set('HTML.Parent', 'span'); $this->assertResult( 'Par @@ -498,7 +498,7 @@ Bar", } function testErrorNeeded() { - $this->config->set('HTML', 'Allowed', 'b'); + $this->config->set('HTML.Allowed', 'b'); $this->expectError('Cannot enable AutoParagraph injector because p is not allowed'); $this->assertResult('foobar'); } diff --git a/tests/HTMLPurifier/Injector/DisplayLinkURITest.php b/tests/HTMLPurifier/Injector/DisplayLinkURITest.php index 3e8fbfbe..1629d9bd 100644 --- a/tests/HTMLPurifier/Injector/DisplayLinkURITest.php +++ b/tests/HTMLPurifier/Injector/DisplayLinkURITest.php @@ -5,7 +5,7 @@ class HTMLPurifier_Injector_DisplayLinkURITest extends HTMLPurifier_InjectorHarn function setup() { parent::setup(); - $this->config->set('AutoFormat', 'DisplayLinkURI', true); + $this->config->set('AutoFormat.DisplayLinkURI', true); } function testBasicLink() { diff --git a/tests/HTMLPurifier/Injector/LinkifyTest.php b/tests/HTMLPurifier/Injector/LinkifyTest.php index 707f09b5..e66f0eb9 100644 --- a/tests/HTMLPurifier/Injector/LinkifyTest.php +++ b/tests/HTMLPurifier/Injector/LinkifyTest.php @@ -5,7 +5,7 @@ class HTMLPurifier_Injector_LinkifyTest extends HTMLPurifier_InjectorHarness function setup() { parent::setup(); - $this->config->set('AutoFormat', 'Linkify', true); + $this->config->set('AutoFormat.Linkify', true); } function testLinkifyURLInRootNode() { @@ -36,7 +36,7 @@ class HTMLPurifier_Injector_LinkifyTest extends HTMLPurifier_InjectorHarness } function testNeeded() { - $this->config->set('HTML', 'Allowed', 'b'); + $this->config->set('HTML.Allowed', 'b'); $this->expectError('Cannot enable Linkify injector because a is not allowed'); $this->assertResult('http://example.com/'); } diff --git a/tests/HTMLPurifier/Injector/PurifierLinkifyTest.php b/tests/HTMLPurifier/Injector/PurifierLinkifyTest.php index f3ae67ad..bcb7903c 100644 --- a/tests/HTMLPurifier/Injector/PurifierLinkifyTest.php +++ b/tests/HTMLPurifier/Injector/PurifierLinkifyTest.php @@ -5,8 +5,8 @@ class HTMLPurifier_Injector_PurifierLinkifyTest extends HTMLPurifier_InjectorHar function setup() { parent::setup(); - $this->config->set('AutoFormat', 'PurifierLinkify', true); - $this->config->set('AutoFormatParam', 'PurifierLinkifyDocURL', '#%s'); + $this->config->set('AutoFormat.PurifierLinkify', true); + $this->config->set('AutoFormatParam.PurifierLinkifyDocURL', '#%s'); } function testNoTriggerCharacer() { @@ -49,7 +49,7 @@ class HTMLPurifier_Injector_PurifierLinkifyTest extends HTMLPurifier_InjectorHar } function testNeeded() { - $this->config->set('HTML', 'Allowed', 'b'); + $this->config->set('HTML.Allowed', 'b'); $this->expectError('Cannot enable PurifierLinkify injector because a is not allowed'); $this->assertResult('%Namespace.Directive'); } diff --git a/tests/HTMLPurifier/Injector/RemoveEmptyTest.php b/tests/HTMLPurifier/Injector/RemoveEmptyTest.php index 37c1cbe4..f2152976 100644 --- a/tests/HTMLPurifier/Injector/RemoveEmptyTest.php +++ b/tests/HTMLPurifier/Injector/RemoveEmptyTest.php @@ -5,7 +5,7 @@ class HTMLPurifier_Injector_RemoveEmptyTest extends HTMLPurifier_InjectorHarness public function setup() { parent::setup(); - $this->config->set('AutoFormat', 'RemoveEmpty', true); + $this->config->set('AutoFormat.RemoveEmpty', true); } function testPreserve() { @@ -33,12 +33,12 @@ class HTMLPurifier_Injector_RemoveEmptyTest extends HTMLPurifier_InjectorHarness } function testPreserveId() { - $this->config->set('Attr', 'EnableID', true); + $this->config->set('Attr.EnableID', true); $this->assertResult(''); } function testPreserveName() { - $this->config->set('Attr', 'EnableID', true); + $this->config->set('Attr.EnableID', true); $this->assertResult(''); } diff --git a/tests/HTMLPurifier/Injector/SafeObjectTest.php b/tests/HTMLPurifier/Injector/SafeObjectTest.php index 1a0eab52..59e0493c 100644 --- a/tests/HTMLPurifier/Injector/SafeObjectTest.php +++ b/tests/HTMLPurifier/Injector/SafeObjectTest.php @@ -11,8 +11,8 @@ class HTMLPurifier_Injector_SafeObjectTest extends HTMLPurifier_InjectorHarness function setup() { parent::setup(); // there is no AutoFormat.SafeObject directive - $this->config->set('AutoFormat', 'Custom', array(new HTMLPurifier_Injector_SafeObject())); - $this->config->set('HTML', 'Trusted', true); + $this->config->set('AutoFormat.Custom', array(new HTMLPurifier_Injector_SafeObject())); + $this->config->set('HTML.Trusted', true); } function testPreserve() { diff --git a/tests/HTMLPurifier/LanguageFactoryTest.php b/tests/HTMLPurifier/LanguageFactoryTest.php index 89751a1f..9fea24f4 100644 --- a/tests/HTMLPurifier/LanguageFactoryTest.php +++ b/tests/HTMLPurifier/LanguageFactoryTest.php @@ -15,7 +15,7 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness function test() { - $this->config->set('Core', 'Language', 'en'); + $this->config->set('Core.Language', 'en'); $language = $this->factory->create($this->config, $this->context); $this->assertIsA($language, 'HTMLPurifier_Language'); @@ -30,7 +30,7 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness function testFallback() { - $this->config->set('Core', 'Language', 'en-x-test'); + $this->config->set('Core.Language', 'en-x-test'); $language = $this->factory->create($this->config, $this->context); $this->assertIsA($language, 'HTMLPurifier_Language_en_x_test'); @@ -47,7 +47,7 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness } function testFallbackWithNoClass() { - $this->config->set('Core', 'Language', 'en-x-testmini'); + $this->config->set('Core.Language', 'en-x-testmini'); $language = $this->factory->create($this->config, $this->context); $this->assertIsA($language, 'HTMLPurifier_Language'); $this->assertIdentical($language->code, 'en-x-testmini'); @@ -58,7 +58,7 @@ class HTMLPurifier_LanguageFactoryTest extends HTMLPurifier_Harness } function testNoSuchLanguage() { - $this->config->set('Core', 'Language', 'en-x-testnone'); + $this->config->set('Core.Language', 'en-x-testnone'); $language = $this->factory->create($this->config, $this->context); $this->assertIsA($language, 'HTMLPurifier_Language'); $this->assertIdentical($language->code, 'en-x-testnone'); diff --git a/tests/HTMLPurifier/LexerTest.php b/tests/HTMLPurifier/LexerTest.php index 18c2a787..4866a416 100644 --- a/tests/HTMLPurifier/LexerTest.php +++ b/tests/HTMLPurifier/LexerTest.php @@ -24,26 +24,26 @@ class HTMLPurifier_LexerTest extends HTMLPurifier_Harness // HTMLPurifier_Lexer::create() -------------------------------------------- function test_create() { - $this->config->set('Core', 'MaintainLineNumbers', true); + $this->config->set('Core.MaintainLineNumbers', true); $lexer = HTMLPurifier_Lexer::create($this->config); $this->assertIsA($lexer, 'HTMLPurifier_Lexer_DirectLex'); } function test_create_objectLexerImpl() { - $this->config->set('Core', 'LexerImpl', new HTMLPurifier_Lexer_DirectLex()); + $this->config->set('Core.LexerImpl', new HTMLPurifier_Lexer_DirectLex()); $lexer = HTMLPurifier_Lexer::create($this->config); $this->assertIsA($lexer, 'HTMLPurifier_Lexer_DirectLex'); } function test_create_unknownLexer() { - $this->config->set('Core', 'LexerImpl', 'AsdfAsdf'); + $this->config->set('Core.LexerImpl', 'AsdfAsdf'); $this->expectException(new HTMLPurifier_Exception('Cannot instantiate unrecognized Lexer type AsdfAsdf')); HTMLPurifier_Lexer::create($this->config); } function test_create_incompatibleLexer() { - $this->config->set('Core', 'LexerImpl', 'DOMLex'); - $this->config->set('Core', 'MaintainLineNumbers', true); + $this->config->set('Core.LexerImpl', 'DOMLex'); + $this->config->set('Core.MaintainLineNumbers', true); $this->expectException(new HTMLPurifier_Exception('Cannot use lexer that does not support line numbers with Core.MaintainLineNumbers or Core.CollectErrors (use DirectLex instead)')); HTMLPurifier_Lexer::create($this->config); } @@ -491,7 +491,7 @@ class HTMLPurifier_LexerTest extends HTMLPurifier_Harness } function test_tokenizeHTML_scriptCDATAContents() { - $this->config->set('HTML', 'Trusted', true); + $this->config->set('HTML.Trusted', true); $this->assertTokenization( 'Foo: ', array( diff --git a/tests/HTMLPurifier/Strategy/FixNestingTest.php b/tests/HTMLPurifier/Strategy/FixNestingTest.php index 93299a79..7bbc53a5 100644 --- a/tests/HTMLPurifier/Strategy/FixNestingTest.php +++ b/tests/HTMLPurifier/Strategy/FixNestingTest.php @@ -24,7 +24,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness } function testEscapeBlockInInline() { - $this->config->set('Core', 'EscapeInvalidChildren', true); + $this->config->set('Core.EscapeInvalidChildren', true); $this->assertResult( '
Illegal div.
', '<div>Illegal div.</div>' @@ -78,7 +78,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness } function testChameleonEscapeInvalidBlockInInline() { - $this->config->set('Core', 'EscapeInvalidChildren', true); + $this->config->set('Core.EscapeInvalidChildren', true); $this->assertResult( // alt config '
Not allowed!
', '<div>Not allowed!</div>' @@ -94,19 +94,19 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness } function testPreserveInlineNodeInInlineRootNode() { - $this->config->set('HTML', 'Parent', 'span'); + $this->config->set('HTML.Parent', 'span'); $this->assertResult('Bold'); } function testRemoveBlockNodeInInlineRootNode() { - $this->config->set('HTML', 'Parent', 'span'); + $this->config->set('HTML.Parent', 'span'); $this->assertResult('
Reject
', 'Reject'); } function testInvalidParentError() { // test fallback to div - $this->config->set('HTML', 'Parent', 'obviously-impossible'); - $this->config->set('Cache', 'DefinitionImpl', null); + $this->config->set('HTML.Parent', 'obviously-impossible'); + $this->config->set('Cache.DefinitionImpl', null); $this->expectError('Cannot use unrecognized element as parent'); $this->assertResult('
Accept
'); } @@ -128,7 +128,7 @@ class HTMLPurifier_Strategy_FixNestingTest extends HTMLPurifier_StrategyHarness } function testStrictBlockquoteInHTML401() { - $this->config->set('HTML', 'Doctype', 'HTML 4.01 Strict'); + $this->config->set('HTML.Doctype', 'HTML 4.01 Strict'); $this->assertResult('
text
', '

text

'); } diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjectorTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjectorTest.php index 5b77420e..72e833b7 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjectorTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormed/EndInsertInjectorTest.php @@ -5,7 +5,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjectorTest extends HTMLPur function setUp() { parent::setUp(); $this->obj = new HTMLPurifier_Strategy_MakeWellFormed(); - $this->config->set('AutoFormat', 'Custom', array( + $this->config->set('AutoFormat.Custom', array( new HTMLPurifier_Strategy_MakeWellFormed_EndInsertInjector() )); } diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjectorTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjectorTest.php index e5e46ef6..96c88748 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjectorTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormed/EndRewindInjectorTest.php @@ -5,7 +5,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjectorTest extends HTMLPur function setUp() { parent::setUp(); $this->obj = new HTMLPurifier_Strategy_MakeWellFormed(); - $this->config->set('AutoFormat', 'Custom', array( + $this->config->set('AutoFormat.Custom', array( new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector() )); } @@ -22,7 +22,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjectorTest extends HTMLPur $this->assertResult('asdf',''); } function testDoubled() { - $this->config->set('AutoFormat', 'Custom', array( + $this->config->set('AutoFormat.Custom', array( new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector(), new HTMLPurifier_Strategy_MakeWellFormed_EndRewindInjector(), )); diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjectorTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjectorTest.php index e63ca6b3..770b3d84 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjectorTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormed/SkipInjectorTest.php @@ -5,7 +5,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_SkipInjectorTest extends HTMLPurifier function setUp() { parent::setUp(); $this->obj = new HTMLPurifier_Strategy_MakeWellFormed(); - $this->config->set('AutoFormat', 'Custom', array( + $this->config->set('AutoFormat.Custom', array( new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector() )); } @@ -16,7 +16,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_SkipInjectorTest extends HTMLPurifier $this->assertResult('
', '

'); } function testMultiplyMultiply() { - $this->config->set('AutoFormat', 'Custom', array( + $this->config->set('AutoFormat.Custom', array( new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector(), new HTMLPurifier_Strategy_MakeWellFormed_SkipInjector() )); diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php index c3326c9f..0f96c49b 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormedTest.php @@ -94,7 +94,7 @@ class HTMLPurifier_Strategy_MakeWellFormedTest extends HTMLPurifier_StrategyHarn } function testBlockquoteWithInline() { - $this->config->set('HTML', 'Doctype', 'XHTML 1.0 Strict'); + $this->config->set('HTML.Doctype', 'XHTML 1.0 Strict'); $this->assertResult( // This is actually invalid, but will be fixed by // ChildDef_StrictBlockquote diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php index bf917da2..e825e2e2 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormed_ErrorsTest.php @@ -14,7 +14,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_ErrorsTest extends HTMLPurifier_Strat } function testUnnecessaryEndTagToText() { - $this->config->set('Core', 'EscapeInvalidTags', true); + $this->config->set('Core.EscapeInvalidTags', true); $this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Unnecessary end tag to text'); $this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 0)); $this->invoke(''); @@ -40,7 +40,7 @@ class HTMLPurifier_Strategy_MakeWellFormed_ErrorsTest extends HTMLPurifier_Strat } function testStrayEndTagToText() { - $this->config->set('Core', 'EscapeInvalidTags', true); + $this->config->set('Core.EscapeInvalidTags', true); $this->expectErrorCollection(E_WARNING, 'Strategy_MakeWellFormed: Stray end tag to text'); $this->expectContext('CurrentToken', new HTMLPurifier_Token_End('b', array(), 1, 3)); $this->invoke(''); diff --git a/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php b/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php index 05d01bfc..123cff35 100644 --- a/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php +++ b/tests/HTMLPurifier/Strategy/MakeWellFormed_InjectorTest.php @@ -6,9 +6,9 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str function setUp() { parent::setUp(); $this->obj = new HTMLPurifier_Strategy_MakeWellFormed(); - $this->config->set('AutoFormat', 'AutoParagraph', true); - $this->config->set('AutoFormat', 'Linkify', true); - $this->config->set('AutoFormat', 'RemoveEmpty', true); + $this->config->set('AutoFormat.AutoParagraph', true); + $this->config->set('AutoFormat.Linkify', true); + $this->config->set('AutoFormat.RemoveEmpty', true); generate_mock_once('HTMLPurifier_Injector'); } @@ -26,21 +26,21 @@ class HTMLPurifier_Strategy_MakeWellFormed_InjectorTest extends HTMLPurifier_Str $mock->expectAt(1, 'handleEnd', array($i)); $mock->expectCallCount('handleEnd', 2); $mock->setReturnValue('getRewind', false); - $this->config->set('AutoFormat', 'AutoParagraph', false); - $this->config->set('AutoFormat', 'Linkify', false); - $this->config->set('AutoFormat', 'Custom', array($mock)); + $this->config->set('AutoFormat.AutoParagraph', false); + $this->config->set('AutoFormat.Linkify', false); + $this->config->set('AutoFormat.Custom', array($mock)); $this->assertResult('asdf', 'asdf'); } function testErrorRequiredElementNotAllowed() { - $this->config->set('HTML', 'Allowed', ''); + $this->config->set('HTML.Allowed', ''); $this->expectError('Cannot enable AutoParagraph injector because p is not allowed'); $this->expectError('Cannot enable Linkify injector because a is not allowed'); $this->assertResult('Foobar'); } function testErrorRequiredAttributeNotAllowed() { - $this->config->set('HTML', 'Allowed', 'a,p'); + $this->config->set('HTML.Allowed', 'a,p'); $this->expectError('Cannot enable Linkify injector because a.href is not allowed'); $this->assertResult('

http://example.com

'); } diff --git a/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php b/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php index 125fc81b..3b9a6449 100644 --- a/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php +++ b/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php @@ -38,7 +38,7 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_Strat } function testRemoveOnlyScriptTagsLegacy() { - $this->config->set('Core', 'RemoveScriptContents', false); + $this->config->set('Core.RemoveScriptContents', false); $this->assertResult( '', 'alert();' @@ -46,7 +46,7 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_Strat } function testRemoveOnlyScriptTags() { - $this->config->set('Core', 'HiddenElements', array()); + $this->config->set('Core.HiddenElements', array()); $this->assertResult( '', 'alert();' @@ -62,13 +62,13 @@ class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_Strat } function testPreserveInvalidImgWhenRemovalIsDisabled() { - $this->config->set('Core', 'RemoveInvalidImg', false); + $this->config->set('Core.RemoveInvalidImg', false); $this->assertResult(''); } function testTextifyCommentedScriptContents() { - $this->config->set('HTML', 'Trusted', true); - $this->config->set('Output', 'CommentScriptContents', false); // simplify output + $this->config->set('HTML.Trusted', true); + $this->config->set('Output.CommentScriptContents', false); // simplify output $this->assertResult( '