0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 15:28:40 +00:00

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
This commit is contained in:
Edward Z. Yang 2007-01-16 22:22:08 +00:00
parent 3a73c2cf04
commit 61f852d429
22 changed files with 60 additions and 28 deletions

View File

@ -109,7 +109,7 @@ class HTMLPurifier
$config = $config ? HTMLPurifier_Config::create($config) : $this->config; $config = $config ? HTMLPurifier_Config::create($config) : $this->config;
$context =& new HTMLPurifier_Context(); $context = new HTMLPurifier_Context();
$html = $this->encoder->convertToUTF8($html, $config, $context); $html = $this->encoder->convertToUTF8($html, $config, $context);
// purified HTML // purified HTML

View File

@ -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 // no need to validate the scheme's fmt since we do that when we
// retrieve the specific scheme object from the registry // retrieve the specific scheme object from the registry
$scheme = ctype_lower($scheme) ? $scheme : strtolower($scheme); $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 if (!$scheme_obj) return false; // invalid scheme, clean it out
} else { } else {
$scheme_obj =& $registry->getScheme( $scheme_obj = $registry->getScheme(
$config->get('URI', 'DefaultScheme'), $config, $context $config->get('URI', 'DefaultScheme'), $config, $context
); );
} }

View File

@ -20,7 +20,7 @@ HTMLPurifier_ConfigSchema::defineAllowedValues(
class HTMLPurifier_AttrTransform_BdoDir extends HTMLPurifier_AttrTransform class HTMLPurifier_AttrTransform_BdoDir extends HTMLPurifier_AttrTransform
{ {
function transform($attr, $config, $context) { function transform($attr, $config, &$context) {
if (isset($attr['dir'])) return $attr; if (isset($attr['dir'])) return $attr;
$attr['dir'] = $config->get('Attr', 'DefaultTextDir'); $attr['dir'] = $config->get('Attr', 'DefaultTextDir');
return $attr; return $attr;

View File

@ -25,7 +25,7 @@ HTMLPurifier_ConfigSchema::define(
class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform class HTMLPurifier_AttrTransform_ImgRequired extends HTMLPurifier_AttrTransform
{ {
function transform($attr, $config, $context) { function transform($attr, $config, &$context) {
$src = true; $src = true;
if (!isset($attr['src'])) { if (!isset($attr['src'])) {

View File

@ -10,7 +10,7 @@ require_once 'HTMLPurifier/AttrTransform.php';
class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform class HTMLPurifier_AttrTransform_Lang extends HTMLPurifier_AttrTransform
{ {
function transform($attr, $config, $context) { function transform($attr, $config, &$context) {
$lang = isset($attr['lang']) ? $attr['lang'] : false; $lang = isset($attr['lang']) ? $attr['lang'] : false;
$xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false; $xml_lang = isset($attr['xml:lang']) ? $attr['xml:lang'] : false;

View File

@ -8,7 +8,7 @@ require_once 'HTMLPurifier/AttrTransform.php';
class HTMLPurifier_AttrTransform_TextAlign class HTMLPurifier_AttrTransform_TextAlign
extends HTMLPurifier_AttrTransform { extends HTMLPurifier_AttrTransform {
function transform($attr, $config, $context) { function transform($attr, $config, &$context) {
if (!isset($attr['align'])) return $attr; if (!isset($attr['align'])) return $attr;

View File

@ -46,6 +46,7 @@ class HTMLPurifier_Config
/** /**
* Convenience constructor that creates a config object based on a mixed var * Convenience constructor that creates a config object based on a mixed var
* @static
* @param mixed $config Variable that defines the state of the config * @param mixed $config Variable that defines the state of the config
* object. Can be: a HTMLPurifier_Config() object or * object. Can be: a HTMLPurifier_Config() object or
* an array of directives based on loadArray(). * an array of directives based on loadArray().
@ -60,6 +61,7 @@ class HTMLPurifier_Config
/** /**
* Convenience constructor that creates a default configuration object. * Convenience constructor that creates a default configuration object.
* @static
* @return Default HTMLPurifier_Config object. * @return Default HTMLPurifier_Config object.
*/ */
function createDefault() { function createDefault() {

View File

@ -67,6 +67,7 @@ class HTMLPurifier_ConfigSchema {
/** /**
* Retrieves an instance of the application-wide configuration definition. * Retrieves an instance of the application-wide configuration definition.
* @static
*/ */
function &instance($prototype = null) { function &instance($prototype = null) {
static $instance; static $instance;
@ -81,6 +82,7 @@ class HTMLPurifier_ConfigSchema {
/** /**
* Defines a directive for configuration * Defines a directive for configuration
* @static
* @warning Will fail of directive's namespace is defined * @warning Will fail of directive's namespace is defined
* @param $namespace Namespace the directive is in * @param $namespace Namespace the directive is in
* @param $name Key of directive * @param $name Key of directive
@ -144,6 +146,7 @@ class HTMLPurifier_ConfigSchema {
/** /**
* Defines a namespace for directives to be put into. * Defines a namespace for directives to be put into.
* @static
* @param $namespace Namespace's name * @param $namespace Namespace's name
* @param $description Description of the namespace * @param $description Description of the namespace
*/ */
@ -169,6 +172,7 @@ class HTMLPurifier_ConfigSchema {
* *
* Directive value aliases are convenient for developers because it lets * Directive value aliases are convenient for developers because it lets
* them set a directive to several values and get the same result. * them set a directive to several values and get the same result.
* @static
* @param $namespace Directive's namespace * @param $namespace Directive's namespace
* @param $name Name of Directive * @param $name Name of Directive
* @param $alias Name of aliased value * @param $alias Name of aliased value
@ -200,6 +204,7 @@ class HTMLPurifier_ConfigSchema {
/** /**
* Defines a set of allowed values for a directive. * Defines a set of allowed values for a directive.
* @static
* @param $namespace Namespace of directive * @param $namespace Namespace of directive
* @param $name Name of directive * @param $name Name of directive
* @param $allowed_values Arraylist of allowed values * @param $allowed_values Arraylist of allowed values

View File

@ -48,6 +48,7 @@ class HTMLPurifier_Encoder
* It will parse according to UTF-8 and return a valid UTF8 string, with * It will parse according to UTF-8 and return a valid UTF8 string, with
* non-SGML codepoints excluded. * non-SGML codepoints excluded.
* *
* @static
* @note Just for reference, the non-SGML code points are 0 to 31 and * @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 * 127 to 159, inclusive. However, we allow code points 9, 10
* and 13, which are the tab, line feed and carriage return * 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. * Translates a Unicode codepoint into its corresponding UTF-8 character.
* @static
* @note Based on Feyd's function at * @note Based on Feyd's function at
* <http://forums.devnetwork.net/viewtopic.php?p=191404#191404>, * <http://forums.devnetwork.net/viewtopic.php?p=191404#191404>,
* which is in public domain. * which is in public domain.

View File

@ -26,6 +26,7 @@ class HTMLPurifier_EntityLookup {
/** /**
* Retrieves sole instance of the object. * Retrieves sole instance of the object.
* @static
* @param Optional prototype of custom lookup table to overload with. * @param Optional prototype of custom lookup table to overload with.
*/ */
function instance($prototype = false) { function instance($prototype = false) {

View File

@ -300,9 +300,6 @@ class HTMLPurifier_HTMLDefinition
$this->info['b']->child = $this->info['b']->child =
$this->info['big']->child = $this->info['big']->child =
$this->info['small']->child= $this->info['small']->child=
$this->info['u']->child =
$this->info['s']->child =
$this->info['strike']->child =
$this->info['bdo']->child = $this->info['bdo']->child =
$this->info['span']->child = $this->info['span']->child =
$this->info['dt']->child = $this->info['dt']->child =
@ -314,6 +311,12 @@ class HTMLPurifier_HTMLDefinition
$this->info['h5']->child = $this->info['h5']->child =
$this->info['h6']->child = $e_Inline; $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 // the only three required definitions, besides custom table code
$this->info['ol']->child = $this->info['ol']->child =
$this->info['ul']->child = new HTMLPurifier_ChildDef_Required('li'); $this->info['ul']->child = new HTMLPurifier_ChildDef_Required('li');
@ -355,10 +358,12 @@ class HTMLPurifier_HTMLDefinition
// reuses $e_Inline and $e_Block // reuses $e_Inline and $e_Block
foreach ($e_Inline->elements as $name => $bool) { foreach ($e_Inline->elements as $name => $bool) {
if ($name == '#PCDATA') continue; if ($name == '#PCDATA') continue;
if (!isset($this->info[$name])) continue;
$this->info[$name]->type = 'inline'; $this->info[$name]->type = 'inline';
} }
foreach ($e_Block->elements as $name => $bool) { foreach ($e_Block->elements as $name => $bool) {
if (!isset($this->info[$name])) continue;
$this->info[$name]->type = 'block'; $this->info[$name]->type = 'block';
} }

View File

@ -138,6 +138,8 @@ class HTMLPurifier_Lexer
* default with your own implementation. A copy/reference of the prototype * default with your own implementation. A copy/reference of the prototype
* lexer will now be returned when you request a new lexer. * lexer will now be returned when you request a new lexer.
* *
* @static
*
* @note * @note
* Though it is possible to call this factory method from subclasses, * Though it is possible to call this factory method from subclasses,
* such usage is not recommended. * such usage is not recommended.
@ -166,6 +168,7 @@ class HTMLPurifier_Lexer
/** /**
* Translates CDATA sections into regular sections (through escaping). * Translates CDATA sections into regular sections (through escaping).
* *
* @static
* @protected * @protected
* @param $string HTML string to process. * @param $string HTML string to process.
* @returns HTML with CDATA sections escaped. * @returns HTML with CDATA sections escaped.
@ -181,6 +184,7 @@ class HTMLPurifier_Lexer
/** /**
* Callback function for escapeCDATA() that does the work. * Callback function for escapeCDATA() that does the work.
* *
* @static
* @warning Though this is public in order to let the callback happen, * @warning Though this is public in order to let the callback happen,
* calling it directly is not recommended. * calling it directly is not recommended.
* @params $matches PCRE matches array, with index 0 the entire match * @params $matches PCRE matches array, with index 0 the entire match

View File

@ -88,6 +88,11 @@ class HTMLPurifier_Lexer_DOMLex extends HTMLPurifier_Lexer
} elseif ($node->nodeType === XML_COMMENT_NODE) { } elseif ($node->nodeType === XML_COMMENT_NODE) {
$tokens[] = $this->factory->createComment($node->data); $tokens[] = $this->factory->createComment($node->data);
return; return;
} elseif (
// not-well tested: there may be other nodes we have to grab
$node->nodeType !== XML_ELEMENT_NODE
) {
return;
} }
$attr = $node->hasAttributes() ? $attr = $node->hasAttributes() ?

View File

@ -37,7 +37,7 @@ class HTMLPurifier_Lexer_PEARSax3 extends HTMLPurifier_Lexer
$string = $this->normalize($string, $config, $context); $string = $this->normalize($string, $config, $context);
$parser=& new XML_HTMLSax3(); $parser = new XML_HTMLSax3();
$parser->set_object($this); $parser->set_object($this);
$parser->set_element_handler('openHandler','closeHandler'); $parser->set_element_handler('openHandler','closeHandler');
$parser->set_data_handler('dataHandler'); $parser->set_data_handler('dataHandler');

View File

@ -10,10 +10,10 @@ class HTMLPurifier_Printer_HTMLDefinition extends HTMLPurifier_Printer
*/ */
var $def; var $def;
function render(&$config) { function render($config) {
$ret = ''; $ret = '';
$this->config =& $config; $this->config =& $config;
$this->def =& $config->getHTMLDefinition(); $this->def = $config->getHTMLDefinition();
$def =& $this->def; $def =& $this->def;
$ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer')); $ret .= $this->start('div', array('class' => 'HTMLPurifier_Printer'));

View File

@ -32,6 +32,7 @@ class HTMLPurifier_URISchemeRegistry
/** /**
* Retrieve sole instance of the registry. * Retrieve sole instance of the registry.
* @static
* @param $prototype Optional prototype to overload sole instance with, * @param $prototype Optional prototype to overload sole instance with,
* or bool true to reset to default registry. * or bool true to reset to default registry.
* @note Pass a registry object $prototype with a compatible interface and * @note Pass a registry object $prototype with a compatible interface and

View File

@ -3,6 +3,7 @@
header('Content-type: text/html; charset=UTF-8'); header('Content-type: text/html; charset=UTF-8');
require_once '../library/HTMLPurifier.auto.php'; require_once '../library/HTMLPurifier.auto.php';
error_reporting(E_ALL);
function escapeHTML($string) { function escapeHTML($string) {
$string = HTMLPurifier_Encoder::cleanUTF8($string); $string = HTMLPurifier_Encoder::cleanUTF8($string);

View File

@ -70,6 +70,9 @@ class Debugger
$this->add_pre = !extension_loaded('xdebug'); $this->add_pre = !extension_loaded('xdebug');
} }
/**
* @static
*/
function &instance() { function &instance() {
static $soleInstance = false; static $soleInstance = false;
if (!$soleInstance) $soleInstance = new Debugger(); if (!$soleInstance) $soleInstance = new Debugger();

View File

@ -28,10 +28,10 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness
// first test: value properly validates on first definition // first test: value properly validates on first definition
// so second def is never called // so second def is never called
$def1 =& new HTMLPurifier_AttrDefMock($this); $def1 = new HTMLPurifier_AttrDefMock($this);
$def2 =& new HTMLPurifier_AttrDefMock($this); $def2 = new HTMLPurifier_AttrDefMock($this);
$defs = array(&$def1, &$def2); $defs = array(&$def1, &$def2);
$def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); $def = new HTMLPurifier_AttrDef_Composite_Testable($defs);
$input = 'FOOBAR'; $input = 'FOOBAR';
$output = 'foobar'; $output = 'foobar';
$def1_params = array($input, $config, $context); $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 // second test, first def fails, second def works
$def1 =& new HTMLPurifier_AttrDefMock($this); $def1 = new HTMLPurifier_AttrDefMock($this);
$def2 =& new HTMLPurifier_AttrDefMock($this); $def2 = new HTMLPurifier_AttrDefMock($this);
$defs = array(&$def1, &$def2); $defs = array(&$def1, &$def2);
$def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); $def = new HTMLPurifier_AttrDef_Composite_Testable($defs);
$input = 'BOOMA'; $input = 'BOOMA';
$output = 'booma'; $output = 'booma';
$def_params = array($input, $config, $context); $def_params = array($input, $config, $context);
@ -67,10 +67,10 @@ class HTMLPurifier_AttrDef_CompositeTest extends HTMLPurifier_AttrDefHarness
// third test, all fail, so composite faiils // third test, all fail, so composite faiils
$def1 =& new HTMLPurifier_AttrDefMock($this); $def1 = new HTMLPurifier_AttrDefMock($this);
$def2 =& new HTMLPurifier_AttrDefMock($this); $def2 = new HTMLPurifier_AttrDefMock($this);
$defs = array(&$def1, &$def2); $defs = array(&$def1, &$def2);
$def =& new HTMLPurifier_AttrDef_Composite_Testable($defs); $def = new HTMLPurifier_AttrDef_Composite_Testable($defs);
$input = 'BOOMA'; $input = 'BOOMA';
$output = false; $output = false;
$def_params = array($input, $config, $context); $def_params = array($input, $config, $context);

View File

@ -206,7 +206,7 @@ class HTMLPurifier_AttrDef_URITest extends HTMLPurifier_AttrDefHarness
$registry =& HTMLPurifier_URISchemeRegistry::instance($fake_registry); $registry =& HTMLPurifier_URISchemeRegistry::instance($fake_registry);
// now, let's add a pseudo-scheme to the 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 // here are the schemes we will support with overloaded mocks
$registry->setReturnReference('getScheme', $this->scheme, array('http', $this->config, $this->context)); $registry->setReturnReference('getScheme', $this->scheme, array('http', $this->config, $this->context));

View File

@ -20,7 +20,7 @@ class HTMLPurifier_ContextTest extends UnitTestCase
$this->assertFalse($this->context->exists('IDAccumulator')); $this->assertFalse($this->context->exists('IDAccumulator'));
$accumulator =& new HTMLPurifier_IDAccumulatorMock($this); $accumulator = new HTMLPurifier_IDAccumulatorMock($this);
$this->context->register('IDAccumulator', $accumulator); $this->context->register('IDAccumulator', $accumulator);
$this->assertTrue($this->context->exists('IDAccumulator')); $this->assertTrue($this->context->exists('IDAccumulator'));

View File

@ -16,7 +16,10 @@ class HTMLPurifier_LexerTest extends UnitTestCase
$this->DirectLex = new HTMLPurifier_Lexer_DirectLex(); $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; $this->_has_pear = true;
require_once 'HTMLPurifier/Lexer/PEARSax3.php'; require_once 'HTMLPurifier/Lexer/PEARSax3.php';
$this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3(); $this->PEARSax3 = new HTMLPurifier_Lexer_PEARSax3();