From 598c5b60c923a5fc1d21324e0b0df726f7038b84 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Fri, 12 Nov 2010 16:15:03 +0000 Subject: [PATCH] Add sanity check against ze1_compatibility_mode. Signed-off-by: Edward Z. Yang --- INSTALL | 1 + NEWS | 4 +++ library/HTMLPurifier.autoload.php | 5 +++ .../HTMLPurifier/PHPT/ze1_compatibility_mode.phpt | 14 +++++++++ tests/PHPT/Section/PRESKIPIF.php | 36 ++++++++++++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 tests/HTMLPurifier/PHPT/ze1_compatibility_mode.phpt create mode 100644 tests/PHPT/Section/PRESKIPIF.php diff --git a/INSTALL b/INSTALL index 2b4069e2..e64ccb0b 100644 --- a/INSTALL +++ b/INSTALL @@ -18,6 +18,7 @@ with these contents. HTML Purifier is PHP 5 only, and is actively tested from PHP 5.0.5 and up. It has no core dependencies with other libraries. PHP 4 support was deprecated on December 31, 2007 with HTML Purifier 3.0.0. +HTML Purifier is not compatible with zend.ze1_compatibility_mode. These optional extensions can enhance the capabilities of HTML Purifier: diff --git a/NEWS b/NEWS index c028c486..a0d2084b 100644 --- a/NEWS +++ b/NEWS @@ -18,6 +18,10 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier - Fix removal of id attributes under certain conditions by ensuring armor attributes are preserved when recreating tags. - Check if schema.ser was corrupted. +- Check if zend.ze1_compatibility_mode is on, and error out if it is. + This safety check is only done for HTMLPurifier.auto.php; if you + are using standalone or the specialized includes files, you're + expected to know what you're doing. 4.2.0, released 2010-09-15 ! Added %Core.RemoveProcessingInstructions, which lets you remove diff --git a/library/HTMLPurifier.autoload.php b/library/HTMLPurifier.autoload.php index 8d401764..62da5b60 100644 --- a/library/HTMLPurifier.autoload.php +++ b/library/HTMLPurifier.autoload.php @@ -3,6 +3,7 @@ /** * @file * Convenience file that registers autoload handler for HTML Purifier. + * It also does some sanity checks. */ if (function_exists('spl_autoload_register') && function_exists('spl_autoload_unregister')) { @@ -18,4 +19,8 @@ if (function_exists('spl_autoload_register') && function_exists('spl_autoload_un } } +if (ini_get('zend.ze1_compatibility_mode')) { + trigger_error("HTML Purifier is not compatible with zend.ze1_compatibility_mode; please turn it off", E_USER_ERROR); +} + // vim: et sw=4 sts=4 diff --git a/tests/HTMLPurifier/PHPT/ze1_compatibility_mode.phpt b/tests/HTMLPurifier/PHPT/ze1_compatibility_mode.phpt new file mode 100644 index 00000000..606d7592 --- /dev/null +++ b/tests/HTMLPurifier/PHPT/ze1_compatibility_mode.phpt @@ -0,0 +1,14 @@ +--TEST-- +Error with zend.ze1_compatibility_mode test +--PRESKIPIF-- += 0) { + echo 'skip - ze1_compatibility_mode not present in PHP 5.3 or later'; +} +--INI-- +zend.ze1_compatibility_mode = 1 +--FILE-- +_data = $data; + $this->_runner_factory = new PHPT_CodeRunner_Factory(); + } + + public function run(PHPT_Case $case) + { + // @todo refactor this code into PHPT_Util class as its used in multiple places + $filename = dirname($case->filename) . '/' . basename($case->filename, '.php') . '.skip.php'; + + // @todo refactor to PHPT_CodeRunner + file_put_contents($filename, $this->_data); + $runner = $this->_runner_factory->factory($case); + $runner->ini = ""; + $response = $runner->run($filename)->output; + unlink($filename); + + if (preg_match('/^skip( - (.*))?/', $response, $matches)) { + $message = !empty($matches[2]) ? $matches[2] : ''; + throw new PHPT_Case_VetoException($message); + } + } + + public function getPriority() + { + return -2; + } +} -- 2.11.4.GIT