diff --git a/NEWS b/NEWS index a3adf89a..d20c92b0 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,8 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier do not honor error_reporting - Add protection against imagecrash attack with CSS height/width - HTMLPurifier::instance() created for consistency, is equivalent to getInstance() +- Fixed and revamped broken ConfigForm smoketest +- Bug with bool/null fields in Printer_ConfigForm fixed . Out-of-date documentation revised . UTF-8 encoding check optimization as suggested by Diego . HTMLPurifier_Error removed in favor of exceptions diff --git a/configdoc/generate.php b/configdoc/generate.php index b0faf72f..3e4a695c 100644 --- a/configdoc/generate.php +++ b/configdoc/generate.php @@ -38,6 +38,7 @@ $configdoc_xml = 'configdoc.xml'; $xml_builder = new HTMLPurifier_ConfigSchema_Builder_Xml(); $xml_builder->openURI($configdoc_xml); $xml_builder->build($interchange); +unset($xml_builder); // free handle $xslt = new ConfigDoc_HTMLXSLTProcessor(); $xslt->importStylesheet(dirname(__FILE__) . "/styles/$style.xsl"); diff --git a/library/HTMLPurifier/Printer/ConfigForm.php b/library/HTMLPurifier/Printer/ConfigForm.php index addda702..172d7bb4 100644 --- a/library/HTMLPurifier/Printer/ConfigForm.php +++ b/library/HTMLPurifier/Printer/ConfigForm.php @@ -194,6 +194,10 @@ class HTMLPurifier_Printer_ConfigForm_NullDecorator extends HTMLPurifier_Printer 'id' => "$name:Null_$ns.$directive", 'onclick' => "toggleWriteability('$name:$ns.$directive',checked)" // INLINE JAVASCRIPT!!!! ); + if ($this->obj instanceof HTMLPurifier_Printer_ConfigForm_bool) { + // modify inline javascript slightly + $attr['onclick'] = "toggleWriteability('$name:Yes_$ns.$directive',checked);toggleWriteability('$name:No_$ns.$directive',checked)"; + } if ($value === null) $attr['checked'] = 'checked'; $ret .= $this->elementEmpty('input', $attr); $ret .= $this->text(' or '); @@ -291,7 +295,8 @@ class HTMLPurifier_Printer_ConfigForm_bool extends HTMLPurifier_Printer { 'id' => "$name:Yes_$ns.$directive", 'value' => '1' ); - if ($value) $attr['checked'] = 'checked'; + if ($value === true) $attr['checked'] = 'checked'; + if ($value === null) $attr['disabled'] = 'disabled'; $ret .= $this->elementEmpty('input', $attr); $ret .= $this->start('label', array('for' => "$name:No_$ns.$directive")); @@ -305,7 +310,8 @@ class HTMLPurifier_Printer_ConfigForm_bool extends HTMLPurifier_Printer { 'id' => "$name:No_$ns.$directive", 'value' => '0' ); - if (!$value) $attr['checked'] = 'checked'; + if ($value === false) $attr['checked'] = 'checked'; + if ($value === null) $attr['disabled'] = 'disabled'; $ret .= $this->elementEmpty('input', $attr); $ret .= $this->end('div'); diff --git a/smoketests/configForm.php b/smoketests/configForm.php index 3bb52060..051472d9 100644 --- a/smoketests/configForm.php +++ b/smoketests/configForm.php @@ -2,31 +2,37 @@ require_once 'common.php'; +// Setup environment +require_once '../extras/HTMLPurifierExtras.auto.php'; +$interchange = HTMLPurifier_ConfigSchema_InterchangeBuilder::buildFromDirectory('test-schema/'); +$interchange->validate(); + if (isset($_GET['doc'])) { - if ( - file_exists('testSchema.html') && - filemtime('testSchema.php') < filemtime('testSchema.html') && - !isset($_GET['purge']) - ) { - echo file_get_contents('testSchema.html'); + // Hijack page generation to supply documentation + + if (file_exists('test-schema.html') && !isset($_GET['purge'])) { + echo file_get_contents('test-schema.html'); exit; } - if (version_compare('5', PHP_VERSION, '>')) exit('Requires PHP 5 or higher.'); - - // setup ConfigDoc environment - require_once '../configdoc/library/ConfigDoc.auto.php'; - - // perform the ConfigDoc generation - $configdoc = new ConfigDoc(); - $html = $configdoc->generate($new_schema, 'plain', array( - 'css' => '../configdoc/styles/plain.css', - 'title' => 'Sample Configuration Documentation' + $style = 'plain'; + $configdoc_xml = 'test-schema.xml'; + + $xml_builder = new HTMLPurifier_ConfigSchema_Builder_Xml(); + $xml_builder->openURI($configdoc_xml); + $xml_builder->build($interchange); + unset($xml_builder); // free handle + + $xslt = new ConfigDoc_HTMLXSLTProcessor(); + $xslt->importStylesheet("../configdoc/styles/$style.xsl"); + $xslt->setParameters(array( + 'css' => '../configdoc/styles/plain.css', )); - $configdoc->cleanup(); + $html = $xslt->transformToHTML($configdoc_xml); - file_put_contents('testSchema.html', $html); + unlink('test-schema.xml'); + file_put_contents('test-schema.html', $html); echo $html; exit; @@ -50,15 +56,11 @@ of directive possible.

style="float:right;"> build($interchange); +HTMLPurifier_ConfigSchema::instance($schema); -// fictional set, attempts to cover every possible data-type -// see source at ConfigTest.php -require_once 'testSchema.php'; -HTMLPurifier_ConfigSchema::instance($custom_schema); - -// cleanup ( this should be rolled into Config ) -$config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config'); +$config = HTMLPurifier_Config::loadArrayFromForm($_GET, 'config'); $printer = new HTMLPurifier_Printer_ConfigForm('config', '?doc#%s'); echo $printer->render($config); @@ -66,7 +68,7 @@ echo $printer->render($config);
 getAll(), true));
+echo htmlspecialchars(var_export($config->getAll(), true));
 ?>
 
diff --git a/smoketests/test-schema/Directive.Allowed.txt b/smoketests/test-schema/Directive.Allowed.txt new file mode 100644 index 00000000..1e89615d --- /dev/null +++ b/smoketests/test-schema/Directive.Allowed.txt @@ -0,0 +1,5 @@ +Directive.Allowed +TYPE: string +DEFAULT: 'apple' +ALLOWED: 'apple', 'orange', 'pear', 'peach', 'mango' +DESCRIPTION: This directive has a constrained set of allowed values. diff --git a/smoketests/test-schema/Directive.Deprecated.txt b/smoketests/test-schema/Directive.Deprecated.txt new file mode 100644 index 00000000..ad84010b --- /dev/null +++ b/smoketests/test-schema/Directive.Deprecated.txt @@ -0,0 +1,6 @@ +Directive.Deprecated +TYPE: int +DEFAULT: 0 +DESCRIPTION: This is a deprecated directive that shouldn't show up on the form. +DEPRECATED-VERSION: 1.0.0 +DEPRECATED-USE: Directive.Allowed diff --git a/smoketests/test-schema/Directive.txt b/smoketests/test-schema/Directive.txt new file mode 100644 index 00000000..854dd286 --- /dev/null +++ b/smoketests/test-schema/Directive.txt @@ -0,0 +1,2 @@ +Directive +DESCRIPTION: Other custom options with directives. \ No newline at end of file diff --git a/smoketests/test-schema/Type.bool.txt b/smoketests/test-schema/Type.bool.txt new file mode 100644 index 00000000..ccc040a3 --- /dev/null +++ b/smoketests/test-schema/Type.bool.txt @@ -0,0 +1,4 @@ +Type.bool +TYPE: bool +DEFAULT: false +DESCRIPTION: The boolean type is true or false. diff --git a/smoketests/test-schema/Type.float.txt b/smoketests/test-schema/Type.float.txt new file mode 100644 index 00000000..8cce21bb --- /dev/null +++ b/smoketests/test-schema/Type.float.txt @@ -0,0 +1,4 @@ +Type.float +TYPE: float +DEFAULT: 3.1415 +DESCRIPTION: The float type is a floating point number. diff --git a/smoketests/test-schema/Type.hash.txt b/smoketests/test-schema/Type.hash.txt new file mode 100644 index 00000000..cf4fe261 --- /dev/null +++ b/smoketests/test-schema/Type.hash.txt @@ -0,0 +1,4 @@ +Type.hash +TYPE: hash +DEFAULT: array('key1' => 'val1', 'key2' => 'val2') +DESCRIPTION: The hash type is an associative array of string keys and string values. diff --git a/smoketests/test-schema/Type.int.txt b/smoketests/test-schema/Type.int.txt new file mode 100644 index 00000000..5a2b1d8a --- /dev/null +++ b/smoketests/test-schema/Type.int.txt @@ -0,0 +1,4 @@ +Type.int +TYPE: int +DEFAULT: 23 +DESCRIPTION: The int type is an signed integer. diff --git a/smoketests/test-schema/Type.istring.txt b/smoketests/test-schema/Type.istring.txt new file mode 100644 index 00000000..c953f7c8 --- /dev/null +++ b/smoketests/test-schema/Type.istring.txt @@ -0,0 +1,4 @@ +Type.istring +TYPE: istring +DEFAULT: 'case insensitive' +DESCRIPTION: The istring type is short (no newlines), must be ASCII and is case-insensitive. diff --git a/smoketests/test-schema/Type.itext.txt b/smoketests/test-schema/Type.itext.txt new file mode 100644 index 00000000..20fe9183 --- /dev/null +++ b/smoketests/test-schema/Type.itext.txt @@ -0,0 +1,4 @@ +Type.itext +TYPE: itext +DEFAULT: "case\ninsensitive\nand\npossibly\nquite\nlong" +DESCRIPTION: The text type has newlines, must be ASCII and is case-insensitive. diff --git a/smoketests/test-schema/Type.list.txt b/smoketests/test-schema/Type.list.txt new file mode 100644 index 00000000..336cd228 --- /dev/null +++ b/smoketests/test-schema/Type.list.txt @@ -0,0 +1,4 @@ +Type.list +TYPE: list +DEFAULT: array('item1', 'item2') +DESCRIPTION: The list type is a numerically indexed array of strings. diff --git a/smoketests/test-schema/Type.lookup.txt b/smoketests/test-schema/Type.lookup.txt new file mode 100644 index 00000000..6cb458a8 --- /dev/null +++ b/smoketests/test-schema/Type.lookup.txt @@ -0,0 +1,4 @@ +Type.lookup +TYPE: lookup +DEFAULT: array('key1' => true, 'key2' => true) +DESCRIPTION: The lookup type acts just like list, except its elements are unique and are checked with isset($var[$key]). diff --git a/smoketests/test-schema/Type.mixed.txt b/smoketests/test-schema/Type.mixed.txt new file mode 100644 index 00000000..a0dfefd6 --- /dev/null +++ b/smoketests/test-schema/Type.mixed.txt @@ -0,0 +1,4 @@ +Type.mixed +TYPE: mixed +DEFAULT: new stdclass() +DESCRIPTION: The mixed type allows any type, and is not form-editable. diff --git a/smoketests/test-schema/Type.nullbool.txt b/smoketests/test-schema/Type.nullbool.txt new file mode 100644 index 00000000..71d94615 --- /dev/null +++ b/smoketests/test-schema/Type.nullbool.txt @@ -0,0 +1,6 @@ +Type.nullbool +TYPE: bool/null +DEFAULT: null +--DESCRIPTION-- +Null booleans need to be treated a little specially. See %Type.nullstring +for information on what the null flag does. diff --git a/smoketests/test-schema/Type.nullstring.txt b/smoketests/test-schema/Type.nullstring.txt new file mode 100644 index 00000000..8dc4fce1 --- /dev/null +++ b/smoketests/test-schema/Type.nullstring.txt @@ -0,0 +1,8 @@ +Type.nullstring +TYPE: string/null +DEFAULT: null +--DESCRIPTION-- +The null type is not a type, but a flag that can be added to any type +making null a valid value for that entry. It's useful for saying, "Let +the software pick the value for me," or "Don't use this element" when +false has a special meaning. diff --git a/smoketests/test-schema/Type.string.txt b/smoketests/test-schema/Type.string.txt new file mode 100644 index 00000000..d4819139 --- /dev/null +++ b/smoketests/test-schema/Type.string.txt @@ -0,0 +1,4 @@ +Type.string +TYPE: string +DEFAULT: 'Case sensitive' +DESCRIPTION: The string type is short (no newlines) and case-sensitive. diff --git a/smoketests/test-schema/Type.text.txt b/smoketests/test-schema/Type.text.txt new file mode 100644 index 00000000..71c38bb3 --- /dev/null +++ b/smoketests/test-schema/Type.text.txt @@ -0,0 +1,4 @@ +Type.text +TYPE: text +DEFAULT: "Case sensitive\nand\npossibly\nquite long..." +DESCRIPTION: The text type has newlines and is case-sensitive. diff --git a/smoketests/test-schema/Type.txt b/smoketests/test-schema/Type.txt new file mode 100644 index 00000000..156664d0 --- /dev/null +++ b/smoketests/test-schema/Type.txt @@ -0,0 +1,2 @@ +Type +DESCRIPTION: Directives demonstration the variable types ConfigSchema supports. diff --git a/smoketests/test-schema/info.ini b/smoketests/test-schema/info.ini new file mode 100644 index 00000000..87af96c6 --- /dev/null +++ b/smoketests/test-schema/info.ini @@ -0,0 +1 @@ +name = "Test Schema" diff --git a/smoketests/testSchema.php b/smoketests/testSchema.php deleted file mode 100644 index e7ec8845..00000000 --- a/smoketests/testSchema.php +++ /dev/null @@ -1,41 +0,0 @@ -addNamespace('Element', 'Chemical substances that cannot be further decomposed'); - -$custom_schema->add('Element', 'Abbr', 'H', 'string', false, 'Abbreviation of element name.'); -$custom_schema->add('Element', 'Name', 'hydrogen', 'istring', false, 'Full name of atoms.'); -$custom_schema->add('Element', 'Number', 1, 'int', false, 'Atomic number, is identity.'); -$custom_schema->add('Element', 'Mass', 1.00794, 'float', false, 'Atomic mass.'); -$custom_schema->add('Element', 'Radioactive', false, 'bool', false, 'Does it have rapid decay?'); -$custom_schema->add('Element', 'Isotopes', array('1' => true, '2' => true, '3' => true), 'lookup', false, - 'What numbers of neutrons for this element have been observed?'); -$custom_schema->add('Element', 'Traits', array('nonmetallic', 'odorless', 'flammable'), 'list', false, - 'What are general properties of the element?'); -$custom_schema->add('Element', 'IsotopeNames', array('1' => 'protium', '2' => 'deuterium', '3' => 'tritium'), 'hash', false, - 'Lookup hash of neutron counts to formal names.'); - -$custom_schema->addNamespace('Instrument', 'Of the musical type.'); - -$custom_schema->add('Instrument', 'Manufacturer', 'Yamaha', 'string', false, 'Who made it?'); -$custom_schema->addAllowedValues('Instrument', 'Manufacturer', array( - 'Yamaha', 'Conn-Selmer', 'Vandoren', 'Laubin', 'Buffet', 'other')); -$custom_schema->addValueAliases('Instrument', 'Manufacturer', array( - 'Selmer' => 'Conn-Selmer')); - -$custom_schema->add('Instrument', 'Family', 'woodwind', 'istring', false, 'What family is it?'); -$custom_schema->addAllowedValues('Instrument', 'Family', array( - 'brass', 'woodwind', 'percussion', 'string', 'keyboard', 'electronic')); -$custom_schema->addValueAliases('Instrument', 'Family', array( - 'synth' => 'electronic')); - -$custom_schema->addNamespace('ReportCard', 'It is for grades.'); -$custom_schema->add('ReportCard', 'English', null, 'string', true, 'Grade from English class.'); -$custom_schema->add('ReportCard', 'Absences', 0, 'int', false, 'How many times missing from school?'); - -$custom_schema->addNamespace('Text', 'This stuff is long, boring, and English.'); -$custom_schema->add('Text', 'AboutUs', 'Nothing much, but this should be decently long so that a textarea would be better', 'text', false, 'Who are we? What are we up to?'); -$custom_schema->add('Text', 'Hash', "not-case-sensitive\nstill-not-case-sensitive\nsuper-not-case-sensitive", 'itext', false, 'This is of limited utility, but of course it ends up being used.'); -