From 61f852d42919e86f73b97f23b3b825bf001c0886 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 16 Jan 2007 22:22:08 +0000 Subject: [PATCH] Merge in PHP5 strict changes that are applicable to PHP4. git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@650 48356398-32a2-884e-a903-53898d9a118a --- library/HTMLPurifier.php | 2 +- library/HTMLPurifier/AttrDef/URI.php | 4 ++-- library/HTMLPurifier/AttrTransform/BdoDir.php | 2 +- library/HTMLPurifier/AttrTransform/ImgRequired.php | 2 +- library/HTMLPurifier/AttrTransform/Lang.php | 2 +- library/HTMLPurifier/AttrTransform/TextAlign.php | 2 +- library/HTMLPurifier/Config.php | 4 +++- library/HTMLPurifier/ConfigSchema.php | 7 ++++++- library/HTMLPurifier/Encoder.php | 2 ++ library/HTMLPurifier/EntityLookup.php | 1 + library/HTMLPurifier/HTMLDefinition.php | 13 +++++++++---- library/HTMLPurifier/Lexer.php | 4 ++++ library/HTMLPurifier/Lexer/DOMLex.php | 5 +++++ library/HTMLPurifier/Lexer/PEARSax3.php | 2 +- library/HTMLPurifier/Printer/HTMLDefinition.php | 4 ++-- library/HTMLPurifier/URISchemeRegistry.php | 1 + smoketests/common.php | 1 + tests/Debugger.php | 3 +++ tests/HTMLPurifier/AttrDef/CompositeTest.php | 18 +++++++++--------- tests/HTMLPurifier/AttrDef/URITest.php | 2 +- tests/HTMLPurifier/ContextTest.php | 2 +- tests/HTMLPurifier/LexerTest.php | 5 ++++- 22 files changed, 60 insertions(+), 28 deletions(-) diff --git a/library/HTMLPurifier.php b/library/HTMLPurifier.php index 88ced00f..c758b439 100644 --- a/library/HTMLPurifier.php +++ b/library/HTMLPurifier.php @@ -109,7 +109,7 @@ class HTMLPurifier $config = $config ? HTMLPurifier_Config::create($config) : $this->config; - $context =& new HTMLPurifier_Context(); + $context = new HTMLPurifier_Context(); $html = $this->encoder->convertToUTF8($html, $config, $context); // purified HTML diff --git a/library/HTMLPurifier/AttrDef/URI.php b/library/HTMLPurifier/AttrDef/URI.php index d5a36434..a3ce6ded 100644 --- a/library/HTMLPurifier/AttrDef/URI.php +++ b/library/HTMLPurifier/AttrDef/URI.php @@ -139,10 +139,10 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef // no need to validate the scheme's fmt since we do that when we // retrieve the specific scheme object from the registry $scheme = ctype_lower($scheme) ? $scheme : strtolower($scheme); - $scheme_obj =& $registry->getScheme($scheme, $config, $context); + $scheme_obj = $registry->getScheme($scheme, $config, $context); if (!$scheme_obj) return false; // invalid scheme, clean it out } else { - $scheme_obj =& $registry->getScheme( + $scheme_obj = $registry->getScheme( $config->get('URI', 'DefaultScheme'), $config, $context ); } diff --git a/library/HTMLPurifier/AttrTransform/BdoDir.php b/library/HTMLPurifier/AttrTransform/BdoDir.php index dd20f26a..0ea5eb6d 100644 --- a/library/HTMLPurifier/AttrTransform/BdoDir.php +++ b/library/HTMLPurifier/AttrTransform/BdoDir.php @@ -20,7 +20,7 @@ HTMLPurifier_ConfigSchema::defineAllowedValues( class HTMLPurifier_AttrTransform_BdoDir extends HTMLPurifier_AttrTransform { - function transform($attr, $config, $context) { + function transform($attr, $config, &$context) { if (isset($attr['dir'])) return $attr; $attr['dir'] = $config->get('Attr', 'DefaultTextDir'); return $attr; diff --git a/library/HTMLPurifier/AttrTransform/ImgRequired.php b/library/HTMLPurifier/AttrTransform/ImgRequired.php index c943d696..4ff356d8 100644 --- a/library/HTMLPurifier/AttrTransform/ImgRequired.php +++ b/library/HTMLPurifier/AttrTransform/ImgRequired.php @@ -25,7 +25,7 @@ HTMLPurifier_ConfigSchema::define( class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform { - function transform($attr, $config, $context) { + function transform($attr, $config, &$context) { $src = true; if (!isset($attr['src'])) { diff --git a/library/HTMLPurifier/AttrTransform/Lang.php b/library/HTMLPurifier/AttrTransform/Lang.php index 97fd8064..acb1786a 100644 --- a/library/HTMLPurifier/AttrTransform/Lang.php +++ b/library/HTMLPurifier/AttrTransform/Lang.php @@ -10,7 +10,7 @@ require_once 'HTMLPurifier/AttrTransform.php'; class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform { - function transform($attr, $config, $context) { + function transform($attr, $config, &$context) { $lang = isset($attr['lang']) ? $attr['lang'] : false; $xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false; diff --git a/library/HTMLPurifier/AttrTransform/TextAlign.php b/library/HTMLPurifier/AttrTransform/TextAlign.php index e42354a0..84e5a016 100644 --- a/library/HTMLPurifier/AttrTransform/TextAlign.php +++ b/library/HTMLPurifier/AttrTransform/TextAlign.php @@ -8,7 +8,7 @@ require_once 'HTMLPurifier/AttrTransform.php'; class HTMLPurifier_AttrTransform_TextAlign extends HTMLPurifier_AttrTransform { - function transform($attr, $config, $context) { + function transform($attr, $config, &$context) { if (!isset($attr['align'])) return $attr; diff --git a/library/HTMLPurifier/Config.php b/library/HTMLPurifier/Config.php index 39f62855..43c5681d 100644 --- a/library/HTMLPurifier/Config.php +++ b/library/HTMLPurifier/Config.php @@ -46,6 +46,7 @@ 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(). @@ -60,6 +61,7 @@ class HTMLPurifier_Config /** * Convenience constructor that creates a default configuration object. + * @static * @return Default HTMLPurifier_Config object. */ function createDefault() { @@ -178,4 +180,4 @@ class HTMLPurifier_Config } -?> \ No newline at end of file +?> diff --git a/library/HTMLPurifier/ConfigSchema.php b/library/HTMLPurifier/ConfigSchema.php index 9b3c6e2f..6969c1d2 100644 --- a/library/HTMLPurifier/ConfigSchema.php +++ b/library/HTMLPurifier/ConfigSchema.php @@ -67,6 +67,7 @@ class HTMLPurifier_ConfigSchema { /** * Retrieves an instance of the application-wide configuration definition. + * @static */ function &instance($prototype = null) { static $instance; @@ -81,6 +82,7 @@ class HTMLPurifier_ConfigSchema { /** * Defines a directive for configuration + * @static * @warning Will fail of directive's namespace is defined * @param $namespace Namespace the directive is in * @param $name Key of directive @@ -144,6 +146,7 @@ class HTMLPurifier_ConfigSchema { /** * Defines a namespace for directives to be put into. + * @static * @param $namespace Namespace's name * @param $description Description of the namespace */ @@ -169,6 +172,7 @@ class HTMLPurifier_ConfigSchema { * * Directive value aliases are convenient for developers because it lets * them set a directive to several values and get the same result. + * @static * @param $namespace Directive's namespace * @param $name Name of Directive * @param $alias Name of aliased value @@ -200,6 +204,7 @@ class HTMLPurifier_ConfigSchema { /** * Defines a set of allowed values for a directive. + * @static * @param $namespace Namespace of directive * @param $name Name of directive * @param $allowed_values Arraylist of allowed values @@ -380,4 +385,4 @@ class HTMLPurifier_ConfigEntity_Directive extends HTMLPurifier_ConfigEntity } -?> \ No newline at end of file +?> diff --git a/library/HTMLPurifier/Encoder.php b/library/HTMLPurifier/Encoder.php index 8465c709..d9cc655c 100644 --- a/library/HTMLPurifier/Encoder.php +++ b/library/HTMLPurifier/Encoder.php @@ -48,6 +48,7 @@ class HTMLPurifier_Encoder * It will parse according to UTF-8 and return a valid UTF8 string, with * non-SGML codepoints excluded. * + * @static * @note Just for reference, the non-SGML code points are 0 to 31 and * 127 to 159, inclusive. However, we allow code points 9, 10 * and 13, which are the tab, line feed and carriage return @@ -225,6 +226,7 @@ class HTMLPurifier_Encoder /** * Translates a Unicode codepoint into its corresponding UTF-8 character. + * @static * @note Based on Feyd's function at * , * which is in public domain. diff --git a/library/HTMLPurifier/EntityLookup.php b/library/HTMLPurifier/EntityLookup.php index 9816f865..f950cc22 100644 --- a/library/HTMLPurifier/EntityLookup.php +++ b/library/HTMLPurifier/EntityLookup.php @@ -26,6 +26,7 @@ class HTMLPurifier_EntityLookup { /** * Retrieves sole instance of the object. + * @static * @param Optional prototype of custom lookup table to overload with. */ function instance($prototype = false) { diff --git a/library/HTMLPurifier/HTMLDefinition.php b/library/HTMLPurifier/HTMLDefinition.php index 7ca086a9..8ef4fb0e 100644 --- a/library/HTMLPurifier/HTMLDefinition.php +++ b/library/HTMLPurifier/HTMLDefinition.php @@ -300,9 +300,6 @@ class HTMLPurifier_HTMLDefinition $this->info['b']->child = $this->info['big']->child = $this->info['small']->child= - $this->info['u']->child = - $this->info['s']->child = - $this->info['strike']->child = $this->info['bdo']->child = $this->info['span']->child = $this->info['dt']->child = @@ -314,6 +311,12 @@ class HTMLPurifier_HTMLDefinition $this->info['h5']->child = $this->info['h6']->child = $e_Inline; + if (!$this->strict) { + $this->info['u']->child = + $this->info['s']->child = + $this->info['strike']->child = $e_Inline; + } + // the only three required definitions, besides custom table code $this->info['ol']->child = $this->info['ul']->child = new HTMLPurifier_ChildDef_Required('li'); @@ -355,10 +358,12 @@ class HTMLPurifier_HTMLDefinition // reuses $e_Inline and $e_Block foreach ($e_Inline->elements as $name => $bool) { if ($name == '#PCDATA') continue; + if (!isset($this->info[$name])) continue; $this->info[$name]->type = 'inline'; } foreach ($e_Block->elements as $name => $bool) { + if (!isset($this->info[$name])) continue; $this->info[$name]->type = 'block'; } @@ -648,4 +653,4 @@ class HTMLPurifier_ElementDef } -?> \ No newline at end of file +?> diff --git a/library/HTMLPurifier/Lexer.php b/library/HTMLPurifier/Lexer.php index 31d31d27..122bbb5d 100644 --- a/library/HTMLPurifier/Lexer.php +++ b/library/HTMLPurifier/Lexer.php @@ -138,6 +138,8 @@ class HTMLPurifier_Lexer * default with your own implementation. A copy/reference of the prototype * lexer will now be returned when you request a new lexer. * + * @static + * * @note * Though it is possible to call this factory method from subclasses, * such usage is not recommended. @@ -166,6 +168,7 @@ class HTMLPurifier_Lexer /** * Translates CDATA sections into regular sections (through escaping). * + * @static * @protected * @param $string HTML string to process. * @returns HTML with CDATA sections escaped. @@ -181,6 +184,7 @@ class HTMLPurifier_Lexer /** * Callback function for escapeCDATA() that does the work. * + * @static * @warning Though this is public in order to let the callback happen, * calling it directly is not recommended. * @params $matches PCRE matches array, with index 0 the entire match diff --git a/library/HTMLPurifier/Lexer/DOMLex.php b/library/HTMLPurifier/Lexer/DOMLex.php index 57720457..dcf3caee 100644 --- a/library/HTMLPurifier/Lexer/DOMLex.php +++ b/library/HTMLPurifier/Lexer/DOMLex.php @@ -88,6 +88,11 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer } elseif ($node->nodeType === XML_COMMENT_NODE) { $tokens[] = $this->factory->createComment($node->data); return; + } elseif ( + // not-well tested: there may be other nodes we have to grab + $node->nodeType !== XML_ELEMENT_NODE + ) { + return; } $attr = $node->hasAttributes() ? diff --git a/library/HTMLPurifier/Lexer/PEARSax3.php b/library/HTMLPurifier/Lexer/PEARSax3.php index ccd201a7..18777ef7 100644 --- a/library/HTMLPurifier/Lexer/PEARSax3.php +++ b/library/HTMLPurifier/Lexer/PEARSax3.php @@ -37,7 +37,7 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer $string = $this->normalize($string, $config, $context); - $parser=& new XML_HTMLSax3(); + $parser = new XML_HTMLSax3(); $parser->set_object($this); $parser->set_element_handler('openHandler','closeHandler'); $parser->set_data_handler('dataHandler'); diff --git a/library/HTMLPurifier/Printer/HTMLDefinition.php b/library/HTMLPurifier/Printer/HTMLDefinition.php index c85585fc..2ec297e7 100644 --- a/library/HTMLPurifier/Printer/HTMLDefinition.php +++ b/library/HTMLPurifier/Printer/HTMLDefinition.php @@ -10,10 +10,10 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer */ var $def; - function render(&$config) { + function render($config) { $ret = ''; $this->config =& $config; - $this->def =& $config->getHTMLDefinition(); + $this->def = $config->getHTMLDefinition(); $def =& $this->def; $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer')); diff --git a/library/HTMLPurifier/URISchemeRegistry.php b/library/HTMLPurifier/URISchemeRegistry.php index d9c25259..82fd9601 100644 --- a/library/HTMLPurifier/URISchemeRegistry.php +++ b/library/HTMLPurifier/URISchemeRegistry.php @@ -32,6 +32,7 @@ class HTMLPurifier_URISchemeRegistry /** * Retrieve sole instance of the registry. + * @static * @param $prototype Optional prototype to overload sole instance with, * or bool true to reset to default registry. * @note Pass a registry object $prototype with a compatible interface and diff --git a/smoketests/common.php b/smoketests/common.php index 13cc6e59..ec0267c2 100644 --- a/smoketests/common.php +++ b/smoketests/common.php @@ -3,6 +3,7 @@ header('Content-type: text/html; charset=UTF-8'); require_once '../library/HTMLPurifier.auto.php'; +error_reporting(E_ALL); function escapeHTML($string) { $string = HTMLPurifier_Encoder::cleanUTF8($string); diff --git a/tests/Debugger.php b/tests/Debugger.php index 3213af3c..2ef5ba8e 100644 --- a/tests/Debugger.php +++ b/tests/Debugger.php @@ -70,6 +70,9 @@ class Debugger $this->add_pre = !extension_loaded('xdebug'); } + /** + * @static + */ function &instance() { static $soleInstance = false; if (!$soleInstance) $soleInstance = new Debugger(); diff --git a/tests/HTMLPurifier/AttrDef/CompositeTest.php b/tests/HTMLPurifier/AttrDef/CompositeTest.php index 9c49a289..a61db20c 100644 --- a/tests/HTMLPurifier/AttrDef/CompositeTest.php +++ b/tests/HTMLPurifier/AttrDef/CompositeTest.php @@ -28,10 +28,10 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness // first test: value properly validates on first definition // so second def is never called - $def1 =& new HTMLPurifier_AttrDefMock($this); - $def2 =& new HTMLPurifier_AttrDefMock($this); + $def1 = new HTMLPurifier_AttrDefMock($this); + $def2 = new HTMLPurifier_AttrDefMock($this); $defs = array(&$def1, &$def2); - $def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); + $def = new HTMLPurifier_AttrDef_Composite_Testable($defs); $input = 'FOOBAR'; $output = 'foobar'; $def1_params = array($input, $config, $context); @@ -47,10 +47,10 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness // second test, first def fails, second def works - $def1 =& new HTMLPurifier_AttrDefMock($this); - $def2 =& new HTMLPurifier_AttrDefMock($this); + $def1 = new HTMLPurifier_AttrDefMock($this); + $def2 = new HTMLPurifier_AttrDefMock($this); $defs = array(&$def1, &$def2); - $def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); + $def = new HTMLPurifier_AttrDef_Composite_Testable($defs); $input = 'BOOMA'; $output = 'booma'; $def_params = array($input, $config, $context); @@ -67,10 +67,10 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness // third test, all fail, so composite faiils - $def1 =& new HTMLPurifier_AttrDefMock($this); - $def2 =& new HTMLPurifier_AttrDefMock($this); + $def1 = new HTMLPurifier_AttrDefMock($this); + $def2 = new HTMLPurifier_AttrDefMock($this); $defs = array(&$def1, &$def2); - $def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); + $def = new HTMLPurifier_AttrDef_Composite_Testable($defs); $input = 'BOOMA'; $output = false; $def_params = array($input, $config, $context); diff --git a/tests/HTMLPurifier/AttrDef/URITest.php b/tests/HTMLPurifier/AttrDef/URITest.php index a80c436f..f9a9ab41 100644 --- a/tests/HTMLPurifier/AttrDef/URITest.php +++ b/tests/HTMLPurifier/AttrDef/URITest.php @@ -206,7 +206,7 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness $registry =& HTMLPurifier_URISchemeRegistry::instance($fake_registry); // now, let's add a pseudo-scheme to the registry - $this->scheme =& new HTMLPurifier_URISchemeMock($this); + $this->scheme = new HTMLPurifier_URISchemeMock($this); // here are the schemes we will support with overloaded mocks $registry->setReturnReference('getScheme', $this->scheme, array('http', $this->config, $this->context)); diff --git a/tests/HTMLPurifier/ContextTest.php b/tests/HTMLPurifier/ContextTest.php index 68604d5c..88c0f615 100644 --- a/tests/HTMLPurifier/ContextTest.php +++ b/tests/HTMLPurifier/ContextTest.php @@ -20,7 +20,7 @@ class HTMLPurifier_ContextTest extends UnitTestCase $this->assertFalse($this->context->exists('IDAccumulator')); - $accumulator =& new HTMLPurifier_IDAccumulatorMock($this); + $accumulator = new HTMLPurifier_IDAccumulatorMock($this); $this->context->register('IDAccumulator', $accumulator); $this->assertTrue($this->context->exists('IDAccumulator')); diff --git a/tests/HTMLPurifier/LexerTest.php b/tests/HTMLPurifier/LexerTest.php index a690466b..3e627dab 100644 --- a/tests/HTMLPurifier/LexerTest.php +++ b/tests/HTMLPurifier/LexerTest.php @@ -16,7 +16,10 @@ class HTMLPurifier_LexerTest extends UnitTestCase $this->DirectLex = new HTMLPurifier_Lexer_DirectLex(); - if ( $GLOBALS['HTMLPurifierTest']['PEAR'] ) { + // E_STRICT = 2048, int used for PHP4 compat + if ( $GLOBALS['HTMLPurifierTest']['PEAR'] && + ((error_reporting() & 2048) != 2048) + ) { $this->_has_pear = true; require_once 'HTMLPurifier/Lexer/PEARSax3.php'; $this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3(); -- 2.11.4.GIT