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)); ?>