diff --git a/NEWS b/NEWS index 45758ced..2d52c284 100644 --- a/NEWS +++ b/NEWS @@ -33,6 +33,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier from CSS, but you can enable it using %CSS.AllowImportant ! Support for display and visibility CSS properties added, set %CSS.AllowTricky to true to use them. +! HTML Purifier now has its own Exception hierarchy under HTMLPurifier_Exception. + Developer error (not enduser error) can cause these to be triggered. - Autoclose now operates iteratively, i.e.
now has both span tags closed. - Various HTMLPurifier_Config convenience functions now accept another parameter diff --git a/library/HTMLPurifier.includes.php b/library/HTMLPurifier.includes.php index c8703014..511175c9 100644 --- a/library/HTMLPurifier.includes.php +++ b/library/HTMLPurifier.includes.php @@ -43,6 +43,7 @@ require 'HTMLPurifier/EntityLookup.php'; require 'HTMLPurifier/EntityParser.php'; require 'HTMLPurifier/Error.php'; require 'HTMLPurifier/ErrorCollector.php'; +require 'HTMLPurifier/Exception.php'; require 'HTMLPurifier/Filter.php'; require 'HTMLPurifier/Generator.php'; require 'HTMLPurifier/HTMLDefinition.php'; @@ -122,6 +123,8 @@ require 'HTMLPurifier/ChildDef/Table.php'; require 'HTMLPurifier/ConfigDef/Directive.php'; require 'HTMLPurifier/ConfigDef/DirectiveAlias.php'; require 'HTMLPurifier/ConfigDef/Namespace.php'; +require 'HTMLPurifier/ConfigSchema/Exception.php'; +require 'HTMLPurifier/ConfigSchema/Interchange.php'; require 'HTMLPurifier/ConfigSchema/StringHash.php'; require 'HTMLPurifier/ConfigSchema/StringHashAdapter.php'; require 'HTMLPurifier/ConfigSchema/StringHashParser.php'; diff --git a/library/HTMLPurifier/ConfigSchema/Exception.php b/library/HTMLPurifier/ConfigSchema/Exception.php new file mode 100644 index 00000000..4c51d670 --- /dev/null +++ b/library/HTMLPurifier/ConfigSchema/Exception.php @@ -0,0 +1,9 @@ + 'String', + 'istring' => 'Case-insensitive string', + 'text' => 'Text', + 'itext' => 'Case-insensitive text', + 'int' => 'Integer', + 'float' => 'Float', + 'bool' => 'Boolean', + 'lookup' => 'Lookup array', + 'list' => 'Array list', + 'hash' => 'Associative array', + 'mixed' => 'Mixed' + ); + + /** + * Array of Namespace ID => array(namespace info) + */ + public $namespaces; + + /** + * Array of Directive ID => array(directive info) + */ + public $directives; + + /** + * Adds a namespace array to $namespaces + */ + public function addNamespace($arr) { + if (!isset($arr['ID'])) throw new HTMLPurifier_ConfigSchema_Exception('Namespace must have ID'); + $this->namespaces[$arr['ID']] = $arr; + } + + /** + * Adds a directive array to $directives + */ + public function addDirective($arr) { + if (!isset($arr['ID'])) throw new HTMLPurifier_ConfigSchema_Exception('Directive must have ID'); + $this->directives[$arr['ID']] = $arr; + } + +} diff --git a/library/HTMLPurifier/ConfigSchema/StringHashParser.php b/library/HTMLPurifier/ConfigSchema/StringHashParser.php index fe136fed..b490be52 100644 --- a/library/HTMLPurifier/ConfigSchema/StringHashParser.php +++ b/library/HTMLPurifier/ConfigSchema/StringHashParser.php @@ -32,7 +32,7 @@ class HTMLPurifier_ConfigSchema_StringHashParser public $default = 'ID'; public function parseFile($file) { - if (!file_exists($file)) throw new Exception('File does not exist'); + if (!file_exists($file)) throw new HTMLPurifier_ConfigSchema_Exception('File ' . $file . ' does not exist'); $fh = fopen($file, 'r'); $state = false; $single = false; diff --git a/library/HTMLPurifier/Exception.php b/library/HTMLPurifier/Exception.php new file mode 100644 index 00000000..d36d88e0 --- /dev/null +++ b/library/HTMLPurifier/Exception.php @@ -0,0 +1,11 @@ +interchange = new HTMLPurifier_ConfigSchema_Interchange(); + } + + public function testAddNamespace() { + $this->interchange->addNamespace($v = array( + 'ID' => 'Namespace', + 'Foo' => 'Bar', + )); + $this->assertIdentical($v, $this->interchange->namespaces['Namespace']); + } + + public function testAddNamespaceError() { + try { + $this->interchange->addNamespace(array()); + } catch (HTMLPurifier_ConfigSchema_Exception $e) { + $this->assertIdentical($e->getMessage(), 'Namespace must have ID'); + } + } + + public function testAddDirective() { + $this->interchange->addDirective($v = array( + 'ID' => 'Namespace.Directive', + 'Foo' => 'Bar', + )); + $this->assertIdentical($v, $this->interchange->directives['Namespace.Directive']); + } + + public function testAddDirectiveError() { + try { + $this->interchange->addDirective(array()); + } catch (HTMLPurifier_ConfigSchema_Exception $e) { + $this->assertIdentical($e->getMessage(), 'Directive must have ID'); + } + } + +} diff --git a/tests/HTMLPurifier/ConfigSchema/StringHashParserTest.php b/tests/HTMLPurifier/ConfigSchema/StringHashParserTest.php index 5e6af5d9..746cb9ba 100644 --- a/tests/HTMLPurifier/ConfigSchema/StringHashParserTest.php +++ b/tests/HTMLPurifier/ConfigSchema/StringHashParserTest.php @@ -52,4 +52,12 @@ class HTMLPurifier_ConfigSchema_StringHashParserTest extends UnitTestCase )); } + function testError() { + try { + $this->parser->parseFile('NoExist.txt'); + } catch (HTMLPurifier_ConfigSchema_Exception $e) { + $this->assertIdentical($e->getMessage(), 'File NoExist.txt does not exist'); + } + } + } diff --git a/tests/test_files.php b/tests/test_files.php index dcfe4352..48dcfa7b 100644 --- a/tests/test_files.php +++ b/tests/test_files.php @@ -65,6 +65,7 @@ $test_files[] = 'HTMLPurifier/ChildDef/RequiredTest.php'; $test_files[] = 'HTMLPurifier/ChildDef/StrictBlockquoteTest.php'; $test_files[] = 'HTMLPurifier/ChildDef/TableTest.php'; $test_files[] = 'HTMLPurifier/ConfigSchemaTest.php'; +$test_files[] = 'HTMLPurifier/ConfigSchema/InterchangeTest.php'; $test_files[] = 'HTMLPurifier/ConfigSchema/StringHashAdapterTest.php'; $test_files[] = 'HTMLPurifier/ConfigSchema/StringHashReverseAdapterTest.php'; $test_files[] = 'HTMLPurifier/ConfigSchema/StringHashParserTest.php';