diff --git a/NEWS b/NEWS index 9b546dbe..31ec8718 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,7 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier ! Added %Core.EscapeNonASCIICharacters to workaround loss of Unicode characters while %Core.Encoding is set to a non-UTF-8 encoding. ! Support for configuration directive aliases added +! Config object can now be instantiated from ini files - Replaced version check with functionality check for DOM (thanks Stephen Khoo) . Added smoketest 'all.php', which loads all other smoketests via frames diff --git a/TODO b/TODO index ee219f8d..8942453c 100644 --- a/TODO +++ b/TODO @@ -10,8 +10,6 @@ TODO List 1.4 release # Add hooks for custom behavior (for instance, YouTube preservation) - Aggressive caching - - Upgrade SimpleTest testing code to newest version - ? Rich set* methods and config file loaders for HTMLPurifier_Config ? Configuration profiles: sets of directives that get set with one func call 1.5 release @@ -69,6 +67,9 @@ Unknown release (on a scratch-an-itch basis) - Have 'lang' attribute be checked against official lists ? Semi-lossy dumb alternate character encoding transformations, achieved by encoding all characters that have string entity equivalents + - Upgrade SimpleTest testing code to newest version + - Allow tags to be "armored", an internal flag that protects them + from validation and passes them out unharmed Requested ? Native content compression, whitespace stripping (don't rely on Tidy, make diff --git a/library/HTMLPurifier/Config.php b/library/HTMLPurifier/Config.php index dfc734d7..e71c003a 100644 --- a/library/HTMLPurifier/Config.php +++ b/library/HTMLPurifier/Config.php @@ -48,14 +48,16 @@ class HTMLPurifier_Config * Convenience constructor that creates a config object based on a mixed var * @static * @param mixed $config Variable that defines the state of the config - * object. Can be: a HTMLPurifier_Config() object or - * an array of directives based on loadArray(). + * object. Can be: a HTMLPurifier_Config() object, + * an array of directives based on loadArray(), + * or a string filename of an ini file. * @return Configured HTMLPurifier_Config object */ function create($config) { if (is_a($config, 'HTMLPurifier_Config')) return $config; $ret = HTMLPurifier_Config::createDefault(); - if (is_array($config)) $ret->loadArray($config); + if (is_string($config)) $ret->loadIni($config); + elseif (is_array($config)) $ret->loadArray($config); return $ret; } @@ -193,6 +195,15 @@ class HTMLPurifier_Config } } + /** + * Loads configuration values from an ini file + * @param $filename Name of ini file + */ + function loadIni($filename) { + $array = parse_ini_file($filename, true); + $this->loadArray($array); + } + } ?> diff --git a/tests/HTMLPurifier/ConfigTest-create.ini b/tests/HTMLPurifier/ConfigTest-create.ini new file mode 100644 index 00000000..3441565b --- /dev/null +++ b/tests/HTMLPurifier/ConfigTest-create.ini @@ -0,0 +1,2 @@ +[Cake] +Sprinkles = 42 \ No newline at end of file diff --git a/tests/HTMLPurifier/ConfigTest-loadIni.ini b/tests/HTMLPurifier/ConfigTest-loadIni.ini new file mode 100644 index 00000000..80dba594 --- /dev/null +++ b/tests/HTMLPurifier/ConfigTest-loadIni.ini @@ -0,0 +1,4 @@ +[Shortcut] +Copy = q +Cut = t +Paste = p \ No newline at end of file diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php index 4e6aefeb..e04ac416 100644 --- a/tests/HTMLPurifier/ConfigTest.php +++ b/tests/HTMLPurifier/ConfigTest.php @@ -199,6 +199,23 @@ class HTMLPurifier_ConfigTest extends UnitTestCase } + function test_loadIni() { + + CS::defineNamespace('Shortcut', 'Keyboard shortcuts for commands'); + CS::define('Shortcut', 'Copy', 'c', 'istring', 'Copy text'); + CS::define('Shortcut', 'Paste', 'v', 'istring', 'Paste clipboard'); + CS::define('Shortcut', 'Cut', 'x', 'istring', 'Cut text'); + + $config = HTMLPurifier_Config::createDefault(); + + $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'); + + } + function test_getDefinition() { // we actually want to use the old copy, because the definition @@ -274,6 +291,10 @@ class HTMLPurifier_ConfigTest extends UnitTestCase $created_config = HTMLPurifier_Config::create(array('Cake.Sprinkles' => 42)); $this->assertEqual($config, $created_config); + // test loadIni + $created_config = HTMLPurifier_Config::create(dirname(__FILE__) . '/ConfigTest-create.ini'); + $this->assertEqual($config, $created_config); + } }