$config = HTMLPurifier_Config::createDefault(); $config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial'); $config->set('HTML', 'DefinitionRev', 1); -$def =& $config->getHTMLDefinition(true);+$def = $config->getHTMLDefinition(true);
Assuming that HTML Purifier has already been properly loaded (hint: @@ -214,7 +214,7 @@ $def =& $config->getHTMLDefinition(true); $config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial'); $config->set('HTML', 'DefinitionRev', 1); $config->set('Core', 'DefinitionCache', null); // remove this later! -$def =& $config->getHTMLDefinition(true); +$def = $config->getHTMLDefinition(true);
A few things should be mentioned about the caching mechanism before @@ -270,7 +270,7 @@ $def =& $config->getHTMLDefinition(true); $config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial'); $config->set('HTML', 'DefinitionRev', 1); $config->set('Core', 'DefinitionCache', null); // remove this later! -$def =& $config->getHTMLDefinition(true); +$def = $config->getHTMLDefinition(true); $def->addAttribute('a', 'target', 'Enum#_blank,_self,_target,_top');
@@ -388,7 +388,7 @@ $def =& $config->getHTMLDefinition(true);
$config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial');
$config->set('HTML', 'DefinitionRev', 1);
$config->set('Core', 'DefinitionCache', null); // remove this later!
-$def =& $config->getHTMLDefinition(true);
+$def = $config->getHTMLDefinition(true);
$def->addAttribute('a', 'target', new HTMLPurifier_AttrDef_Enum(
array('_blank','_self','_target','_top')
));
@@ -735,11 +735,11 @@ $def =& $config->getHTMLDefinition(true);
$config->set('HTML', 'DefinitionID', 'enduser-customize.html tutorial');
$config->set('HTML', 'DefinitionRev', 1);
$config->set('Core', 'DefinitionCache', null); // remove this later!
-$def =& $config->getHTMLDefinition(true);
+$def = $config->getHTMLDefinition(true);
$def->addAttribute('a', 'target', new HTMLPurifier_AttrDef_Enum(
array('_blank','_self','_target','_top')
));
-$form =& $def->addElement(
+$form = $def->addElement(
'form', // name
'Block', // content set
'Flow', // allowed children
diff --git a/docs/enduser-uri-filter.html b/docs/enduser-uri-filter.html
index edd8848f..b0a377a4 100644
--- a/docs/enduser-uri-filter.html
+++ b/docs/enduser-uri-filter.html
@@ -35,7 +35,7 @@
{
public $name = 'NameOfFilter';
public function prepare($config) {}
- public function filter(&$uri, $config, &$context) {}
+ public function filter(&$uri, $config, $context) {}
}
@@ -60,8 +60,8 @@
public function HTMLPurifier_URI($scheme, $userinfo, $host, $port, $path, $query, $fragment);
public function toString();
public function copy();
- public function getSchemeObj($config, &$context);
- public function validate($config, &$context);
+ public function getSchemeObj($config, $context);
+ public function validate($config, $context);
}
@@ -139,7 +139,7 @@
class HTMLPurifier_URIFilter_ConvertIDNToPunycode extends HTMLPurifier_URIFilter
{
public $name = 'ConvertIDNToPunycode';
- public function filter(&$uri, $config, &$context) {
+ public function filter(&$uri, $config, $context) {
if (is_null($uri->host)) return true;
if ($uri->host == utf8_decode($uri->host)) {
// is ASCII, abort
@@ -163,7 +163,7 @@
to use it. Fortunately, this part's simple:
$uri =& $config->getDefinition('URI'); +diff --git a/library/HTMLPurifier.includes.php b/library/HTMLPurifier.includes.php index b3985c77..3b897a35 100644 --- a/library/HTMLPurifier.includes.php +++ b/library/HTMLPurifier.includes.php @@ -41,7 +41,6 @@ require 'HTMLPurifier/ElementDef.php'; require 'HTMLPurifier/Encoder.php'; require 'HTMLPurifier/EntityLookup.php'; require 'HTMLPurifier/EntityParser.php'; -require 'HTMLPurifier/Error.php'; require 'HTMLPurifier/ErrorCollector.php'; require 'HTMLPurifier/Exception.php'; require 'HTMLPurifier/Filter.php'; diff --git a/library/HTMLPurifier.php b/library/HTMLPurifier.php index d447b6d8..59f27ae6 100644 --- a/library/HTMLPurifier.php +++ b/library/HTMLPurifier.php @@ -207,9 +207,10 @@ class HTMLPurifier /** * Singleton for enforcing just one HTML Purifier in your system * @param $prototype Optional prototype HTMLPurifier instance to - * overload singleton with. + * overload singleton with, or HTMLPurifier_Config + * instance to configure the generated version with. */ - public static function getInstance($prototype = null) { + public static function instance($prototype = null) { if (!self::$instance || $prototype) { if ($prototype instanceof HTMLPurifier) { self::$instance = $prototype; @@ -222,4 +223,11 @@ class HTMLPurifier return self::$instance; } + /** + * @note Backwards compatibility, see instance() + */ + public static function getInstance($prototype = null) { + return HTMLPurifier::instance($prototype); + } + } diff --git a/library/HTMLPurifier.safe-includes.php b/library/HTMLPurifier.safe-includes.php index a110c7c9..4ae5ea7d 100644 --- a/library/HTMLPurifier.safe-includes.php +++ b/library/HTMLPurifier.safe-includes.php @@ -35,7 +35,6 @@ require_once $__dir . '/HTMLPurifier/ElementDef.php'; require_once $__dir . '/HTMLPurifier/Encoder.php'; require_once $__dir . '/HTMLPurifier/EntityLookup.php'; require_once $__dir . '/HTMLPurifier/EntityParser.php'; -require_once $__dir . '/HTMLPurifier/Error.php'; require_once $__dir . '/HTMLPurifier/ErrorCollector.php'; require_once $__dir . '/HTMLPurifier/Exception.php'; require_once $__dir . '/HTMLPurifier/Filter.php'; diff --git a/library/HTMLPurifier/AttrDef.php b/library/HTMLPurifier/AttrDef.php index 1f1ab2f7..2c59a8d7 100644 --- a/library/HTMLPurifier/AttrDef.php +++ b/library/HTMLPurifier/AttrDef.php @@ -70,9 +70,10 @@ abstract class HTMLPurifier_AttrDef * @return Created AttrDef object corresponding to $string */ public function make($string) { - // default implementation, return flyweight of this object - // if overloaded, it is *necessary* for you to clone the - // object (usually by instantiating a new copy) and return that + // default implementation, return a flyweight of this object. + // If $string has an effect on the returned object (i.e. you + // need to overload this method), it is best + // to clone or instantiate new copies. (Instantiation is safer.) return $this; } diff --git a/library/HTMLPurifier/AttrDef/URI.php b/library/HTMLPurifier/AttrDef/URI.php index 13a30a6d..5afc1c1b 100644 --- a/library/HTMLPurifier/AttrDef/URI.php +++ b/library/HTMLPurifier/AttrDef/URI.php @@ -42,7 +42,7 @@ class HTMLPurifier_AttrDef_URI extends HTMLPurifier_AttrDef if (!$result) break; // chained filtering - $uri_def =& $config->getDefinition('URI'); + $uri_def = $config->getDefinition('URI'); $result = $uri_def->filter($uri, $config, $context); if (!$result) break; diff --git a/library/HTMLPurifier/ChildDef.php b/library/HTMLPurifier/ChildDef.php index 3c290fd3..0cc34567 100644 --- a/library/HTMLPurifier/ChildDef.php +++ b/library/HTMLPurifier/ChildDef.php @@ -3,7 +3,7 @@ /** * Defines allowed child nodes and validates tokens against it. */ -class HTMLPurifier_ChildDef +abstract class HTMLPurifier_ChildDef { /** * Type of child definition, usually right-most part of class name lowercase. @@ -34,9 +34,7 @@ class HTMLPurifier_ChildDef * @return bool false to remove parent node * @return array of replacement child tokens */ - public function validateChildren($tokens_of_children, $config, $context) { - trigger_error('Call to abstract function', E_USER_ERROR); - } + abstract public function validateChildren($tokens_of_children, $config, $context); } diff --git a/library/HTMLPurifier/Config.php b/library/HTMLPurifier/Config.php index 2d5900f2..0ed8ecc8 100644 --- a/library/HTMLPurifier/Config.php +++ b/library/HTMLPurifier/Config.php @@ -107,7 +107,7 @@ class HTMLPurifier_Config * @return Default HTMLPurifier_Config object. */ public static function createDefault() { - $definition =& HTMLPurifier_ConfigSchema::instance(); + $definition = HTMLPurifier_ConfigSchema::instance(); $config = new HTMLPurifier_Config($definition); return $config; } @@ -254,21 +254,21 @@ class HTMLPurifier_Config } /** - * Retrieves reference to the HTML definition. + * Retrieves object reference to the HTML definition. * @param $raw Return a copy that has not been setup yet. Must be * called before it's been setup, otherwise won't work. */ - public function &getHTMLDefinition($raw = false) { - $def =& $this->getDefinition('HTML', $raw); - return $def; // prevent PHP 4.4.0 from complaining + public function getHTMLDefinition($raw = false) { + return $this->getDefinition('HTML', $raw); } /** - * Retrieves reference to the CSS definition + * Retrieves object reference to the CSS definition + * @param $raw Return a copy that has not been setup yet. Must be + * called before it's been setup, otherwise won't work. */ - public function &getCSSDefinition($raw = false) { - $def =& $this->getDefinition('CSS', $raw); - return $def; + public function getCSSDefinition($raw = false) { + return $this->getDefinition('CSS', $raw); } /** @@ -276,7 +276,7 @@ class HTMLPurifier_Config * @param $type Type of definition: HTML, CSS, etc * @param $raw Whether or not definition should be returned raw */ - public function &getDefinition($type, $raw = false) { + public function getDefinition($type, $raw = false) { if (!$this->finalized && $this->autoFinalize) $this->finalize(); $factory = HTMLPurifier_DefinitionCacheFactory::instance(); $cache = $factory->create($type, $this); @@ -310,17 +310,13 @@ class HTMLPurifier_Config } elseif ($type == 'URI') { $this->definitions[$type] = new HTMLPurifier_URIDefinition(); } else { - trigger_error("Definition of $type type not supported"); - $false = false; - return $false; + throw new HTMLPurifier_Exception("Definition of $type type not supported"); } // quick abort if raw if ($raw) { if (is_null($this->get($type, 'DefinitionID'))) { // fatally error out if definition ID not set - trigger_error("Cannot retrieve raw version without specifying %$type.DefinitionID", E_USER_ERROR); - $false = new HTMLPurifier_Error(); - return $false; + throw new HTMLPurifier_Exception("Cannot retrieve raw version without specifying %$type.DefinitionID"); } return $this->definitions[$type]; } diff --git a/library/HTMLPurifier/ConfigDef.php b/library/HTMLPurifier/ConfigDef.php index 9490d081..fe35e7a6 100644 --- a/library/HTMLPurifier/ConfigDef.php +++ b/library/HTMLPurifier/ConfigDef.php @@ -3,7 +3,7 @@ /** * Base class for configuration entity */ -class HTMLPurifier_ConfigDef { +abstract class HTMLPurifier_ConfigDef { public $class = false; } diff --git a/library/HTMLPurifier/ConfigSchema.php b/library/HTMLPurifier/ConfigSchema.php index d5aa7e80..bfa84a1b 100644 --- a/library/HTMLPurifier/ConfigSchema.php +++ b/library/HTMLPurifier/ConfigSchema.php @@ -40,7 +40,7 @@ class HTMLPurifier_ConfigSchema { /** * Retrieves an instance of the application-wide configuration definition. */ - public static function &instance($prototype = null) { + public static function instance($prototype = null) { if ($prototype !== null) { HTMLPurifier_ConfigSchema::$singleton = $prototype; } elseif (HTMLPurifier_ConfigSchema::$singleton === null || $prototype === true) { @@ -104,9 +104,8 @@ class HTMLPurifier_ConfigSchema { * @param $allowed Lookup array of allowed values */ public function addAllowedValues($namespace, $name, $allowed) { - $directive =& $this->info[$namespace][$name]; - $type = $directive->type; - $directive->allowed = $allowed; + $type = $this->info[$namespace][$name]->type; + $this->info[$namespace][$name]->allowed = $allowed; } /** @@ -130,21 +129,21 @@ class HTMLPurifier_ConfigSchema { $type = $type_values[0]; $modifier = isset($type_values[1]) ? $type_values[1] : false; $allow_null = ($modifier === 'null'); - $def =& HTMLPurifier_ConfigSchema::instance(); + $def = HTMLPurifier_ConfigSchema::instance(); $def->add($namespace, $name, $default, $type, $allow_null); } /** @see HTMLPurifier_ConfigSchema->addNamespace() */ public static function defineNamespace($namespace, $description) { HTMLPurifier_ConfigSchema::deprecated(__METHOD__); - $def =& HTMLPurifier_ConfigSchema::instance(); + $def = HTMLPurifier_ConfigSchema::instance(); $def->addNamespace($namespace); } /** @see HTMLPurifier_ConfigSchema->addValueAliases() */ public static function defineValueAliases($namespace, $name, $aliases) { HTMLPurifier_ConfigSchema::deprecated(__METHOD__); - $def =& HTMLPurifier_ConfigSchema::instance(); + $def = HTMLPurifier_ConfigSchema::instance(); $def->addValueAliases($namespace, $name, $aliases); } @@ -155,14 +154,14 @@ class HTMLPurifier_ConfigSchema { foreach ($allowed_values as $value) { $allowed[$value] = true; } - $def =& HTMLPurifier_ConfigSchema::instance(); + $def = HTMLPurifier_ConfigSchema::instance(); $def->addAllowedValues($namespace, $name, $allowed); } /** @see HTMLPurifier_ConfigSchema->addAlias() */ public static function defineAlias($namespace, $name, $new_namespace, $new_name) { HTMLPurifier_ConfigSchema::deprecated(__METHOD__); - $def =& HTMLPurifier_ConfigSchema::instance(); + $def = HTMLPurifier_ConfigSchema::instance(); $def->addAlias($namespace, $name, $new_namespace, $new_name); } diff --git a/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php b/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php index 3bc1d409..98a0c9d3 100644 --- a/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php +++ b/library/HTMLPurifier/ConfigSchema/InterchangeBuilder.php @@ -17,7 +17,7 @@ class HTMLPurifier_ConfigSchema_InterchangeBuilder $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder(); $interchange = new HTMLPurifier_ConfigSchema_Interchange(); - if (!$dir) $dir = dirname(__FILE__) . '/schema/'; + if (!$dir) $dir = HTMLPURIFIER_PREFIX . '/HTMLPurifier/ConfigSchema/schema/'; $info = parse_ini_file($dir . 'info.ini'); $interchange->name = $info['name']; diff --git a/library/HTMLPurifier/Context.php b/library/HTMLPurifier/Context.php index d3ca78a0..151a68ed 100644 --- a/library/HTMLPurifier/Context.php +++ b/library/HTMLPurifier/Context.php @@ -4,6 +4,8 @@ * Registry object that contains information about the current context. * @warning Is a bit buggy when variables are set to null: it thinks * they don't exist! So use false instead, please. + * @note Since the variables Context deals with may not be objects, + * references are very important here! Do not remove! */ class HTMLPurifier_Context { @@ -16,7 +18,7 @@ class HTMLPurifier_Context /** * Registers a variable into the context. * @param $name String name - * @param $ref Variable to be registered + * @param $ref Reference to variable to be registered */ public function register($name, &$ref) { if (isset($this->_storage[$name])) { diff --git a/library/HTMLPurifier/DefinitionCacheFactory.php b/library/HTMLPurifier/DefinitionCacheFactory.php index f7dd7daf..2d9aeca3 100644 --- a/library/HTMLPurifier/DefinitionCacheFactory.php +++ b/library/HTMLPurifier/DefinitionCacheFactory.php @@ -20,7 +20,7 @@ class HTMLPurifier_DefinitionCacheFactory /** * Retrieves an instance of global definition cache factory. */ - public static function &instance($prototype = null) { + public static function instance($prototype = null) { static $instance; if ($prototype !== null) { $instance = $prototype; @@ -45,7 +45,7 @@ class HTMLPurifier_DefinitionCacheFactory * @param $name Name of definitions handled by cache * @param $config Instance of HTMLPurifier_Config */ - public function &create($type, $config) { + public function create($type, $config) { $method = $config->get('Cache', 'DefinitionImpl'); if ($method === null) { $null = new HTMLPurifier_DefinitionCache_Null($type); diff --git a/library/HTMLPurifier/DoctypeRegistry.php b/library/HTMLPurifier/DoctypeRegistry.php index ee39bcca..6c969efc 100644 --- a/library/HTMLPurifier/DoctypeRegistry.php +++ b/library/HTMLPurifier/DoctypeRegistry.php @@ -21,9 +21,9 @@ class HTMLPurifier_DoctypeRegistry * @param $modules Modules doctype will load * @param $modules_for_modes Modules doctype will load for certain modes * @param $aliases Alias names for doctype - * @return Reference to registered doctype (usable for further editing) + * @return Editable registered doctype */ - public function ®ister($doctype, $xml = true, $modules = array(), + public function register($doctype, $xml = true, $modules = array(), $tidy_modules = array(), $aliases = array(), $dtd_public = null, $dtd_system = null ) { if (!is_array($modules)) $modules = array($modules); @@ -34,7 +34,7 @@ class HTMLPurifier_DoctypeRegistry $doctype, $xml, $modules, $tidy_modules, $aliases, $dtd_public, $dtd_system ); } - $this->doctypes[$doctype->name] =& $doctype; + $this->doctypes[$doctype->name] = $doctype; $name = $doctype->name; // hookup aliases foreach ($doctype->aliases as $alias) { @@ -51,9 +51,9 @@ class HTMLPurifier_DoctypeRegistry * @note This function resolves aliases * @note When possible, use the more fully-featured make() * @param $doctype Name of doctype - * @return Reference to doctype object + * @return Editable doctype object */ - public function &get($doctype) { + public function get($doctype) { if (isset($this->aliases[$doctype])) $doctype = $this->aliases[$doctype]; if (!isset($this->doctypes[$doctype])) { trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR); diff --git a/library/HTMLPurifier/Encoder.php b/library/HTMLPurifier/Encoder.php index 5ace301f..763684f7 100644 --- a/library/HTMLPurifier/Encoder.php +++ b/library/HTMLPurifier/Encoder.php @@ -281,9 +281,15 @@ class HTMLPurifier_Encoder $encoding = $config->get('Core', 'Encoding'); if ($encoding === 'utf-8') return $str; if ($iconv && !$config->get('Test', 'ForceNoIconv')) { - return @iconv($encoding, 'utf-8//IGNORE', $str); + set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler')); + $str = iconv($encoding, 'utf-8//IGNORE', $str); + restore_error_handler(); + return $str; } elseif ($encoding === 'iso-8859-1') { - return @utf8_encode($str); + set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler')); + $str = utf8_encode($str); + restore_error_handler(); + return $str; } trigger_error('Encoding not supported', E_USER_ERROR); } @@ -302,9 +308,15 @@ class HTMLPurifier_Encoder $str = HTMLPurifier_Encoder::convertToASCIIDumbLossless($str); } if ($iconv && !$config->get('Test', 'ForceNoIconv')) { - return @iconv('utf-8', $encoding . '//IGNORE', $str); + set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler')); + $str = iconv('utf-8', $encoding . '//IGNORE', $str); + restore_error_handler(); + return $str; } elseif ($encoding === 'iso-8859-1') { - return @utf8_decode($str); + set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler')); + $str = utf8_decode($str); + restore_error_handler(); + return $str; } trigger_error('Encoding not supported', E_USER_ERROR); } diff --git a/library/HTMLPurifier/Error.php b/library/HTMLPurifier/Error.php deleted file mode 100644 index 2ca4d732..00000000 --- a/library/HTMLPurifier/Error.php +++ /dev/null @@ -1,7 +0,0 @@ -locale =& $context->get('Locale'); $this->generator =& $context->get('Generator'); - $this->context =& $context; + $this->context = $context; } /** diff --git a/library/HTMLPurifier/Generator.php b/library/HTMLPurifier/Generator.php index 5837c19e..97e8e526 100644 --- a/library/HTMLPurifier/Generator.php +++ b/library/HTMLPurifier/Generator.php @@ -12,19 +12,16 @@ class HTMLPurifier_Generator /** * Bool cache of %HTML.XHTML - * @private */ private $_xhtml = true; /** * Bool cache of %Output.CommentScriptContents - * @private */ private $_scriptFix = false; /** * Cache of HTMLDefinition - * @private */ private $_def; diff --git a/library/HTMLPurifier/HTMLDefinition.php b/library/HTMLPurifier/HTMLDefinition.php index ea03de56..33768396 100644 --- a/library/HTMLPurifier/HTMLDefinition.php +++ b/library/HTMLPurifier/HTMLDefinition.php @@ -95,11 +95,11 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition * HTMLPurifier_AttrTypes for details */ public function addAttribute($element_name, $attr_name, $def) { - $module =& $this->getAnonymousModule(); + $module = $this->getAnonymousModule(); if (!isset($module->info[$element_name])) { - $element =& $module->addBlankElement($element_name); + $element = $module->addBlankElement($element_name); } else { - $element =& $module->info[$element_name]; + $element = $module->info[$element_name]; } $element->attr[$attr_name] = $def; } @@ -109,11 +109,11 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition * @note See HTMLPurifier_HTMLModule::addElement for detailed * parameter and return value descriptions. */ - public function &addElement($element_name, $type, $contents, $attr_collections, $attributes) { - $module =& $this->getAnonymousModule(); + public function addElement($element_name, $type, $contents, $attr_collections, $attributes) { + $module = $this->getAnonymousModule(); // assume that if the user is calling this, the element // is safe. This may not be a good idea - $element =& $module->addElement($element_name, $type, $contents, $attr_collections, $attributes); + $element = $module->addElement($element_name, $type, $contents, $attr_collections, $attributes); return $element; } @@ -123,9 +123,9 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition * @note See HTMLPurifier_HTMLModule::addBlankElement for detailed * parameter and return value descriptions. */ - public function &addBlankElement($element_name) { - $module =& $this->getAnonymousModule(); - $element =& $module->addBlankElement($element_name); + public function addBlankElement($element_name) { + $module = $this->getAnonymousModule(); + $element = $module->addBlankElement($element_name); return $element; } @@ -134,7 +134,7 @@ class HTMLPurifier_HTMLDefinition extends HTMLPurifier_Definition * bust out advanced features without having to make your own * module. */ - public function &getAnonymousModule() { + public function getAnonymousModule() { if (!$this->_anonModule) { $this->_anonModule = new HTMLPurifier_HTMLModule(); $this->_anonModule->name = 'Anonymous'; diff --git a/library/HTMLPurifier/HTMLModule.php b/library/HTMLPurifier/HTMLModule.php index 20989f70..db78983b 100644 --- a/library/HTMLPurifier/HTMLModule.php +++ b/library/HTMLPurifier/HTMLModule.php @@ -116,10 +116,10 @@ class HTMLPurifier_HTMLModule * element? * @param $attr What unique attributes does the element define? * @note See ElementDef for in-depth descriptions of these parameters. - * @return Reference to created element definition object, so you + * @return Created element definition object, so you * can set advanced parameters */ - public function &addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) { + public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) { $this->elements[] = $element; // parse content_model list($content_model_type, $content_model) = $this->parseContents($contents); @@ -140,9 +140,9 @@ class HTMLPurifier_HTMLModule * Convenience function that creates a totally blank, non-standalone * element. * @param $element Name of element to create - * @return Reference to created element + * @return Created element */ - public function &addBlankElement($element) { + public function addBlankElement($element) { if (!isset($this->info[$element])) { $this->elements[] = $element; $this->info[$element] = new HTMLPurifier_ElementDef(); diff --git a/library/HTMLPurifier/HTMLModule/Bdo.php b/library/HTMLPurifier/HTMLModule/Bdo.php index f556c66c..b65057ca 100644 --- a/library/HTMLPurifier/HTMLModule/Bdo.php +++ b/library/HTMLPurifier/HTMLModule/Bdo.php @@ -13,7 +13,7 @@ class HTMLPurifier_HTMLModule_Bdo extends HTMLPurifier_HTMLModule ); public function __construct() { - $bdo =& $this->addElement( + $bdo = $this->addElement( 'bdo', 'Inline', 'Inline', array('Core', 'Lang'), array( 'dir' => 'Enum#ltr,rtl', // required diff --git a/library/HTMLPurifier/HTMLModule/Hypertext.php b/library/HTMLPurifier/HTMLModule/Hypertext.php index c723ce72..4a347e6f 100644 --- a/library/HTMLPurifier/HTMLModule/Hypertext.php +++ b/library/HTMLPurifier/HTMLModule/Hypertext.php @@ -9,7 +9,7 @@ class HTMLPurifier_HTMLModule_Hypertext extends HTMLPurifier_HTMLModule public $name = 'Hypertext'; public function __construct() { - $a =& $this->addElement( + $a = $this->addElement( 'a', 'Inline', 'Inline', 'Common', array( // 'accesskey' => 'Character', diff --git a/library/HTMLPurifier/HTMLModule/Image.php b/library/HTMLPurifier/HTMLModule/Image.php index 7a0b27da..7d2a98c3 100644 --- a/library/HTMLPurifier/HTMLModule/Image.php +++ b/library/HTMLPurifier/HTMLModule/Image.php @@ -11,7 +11,7 @@ class HTMLPurifier_HTMLModule_Image extends HTMLPurifier_HTMLModule public $name = 'Image'; public function __construct() { - $img =& $this->addElement( + $img = $this->addElement( 'img', 'Inline', 'Empty', 'Common', array( 'alt*' => 'Text', diff --git a/library/HTMLPurifier/HTMLModule/Legacy.php b/library/HTMLPurifier/HTMLModule/Legacy.php index c134845c..903273ea 100644 --- a/library/HTMLPurifier/HTMLModule/Legacy.php +++ b/library/HTMLPurifier/HTMLModule/Legacy.php @@ -49,40 +49,40 @@ class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule $align = 'Enum#left,right,center,justify'; - $address =& $this->addBlankElement('address'); + $address = $this->addBlankElement('address'); $address->content_model = 'Inline | #PCDATA | p'; $address->content_model_type = 'optional'; $address->child = false; - $blockquote =& $this->addBlankElement('blockquote'); + $blockquote = $this->addBlankElement('blockquote'); $blockquote->content_model = 'Flow | #PCDATA'; $blockquote->content_model_type = 'optional'; $blockquote->child = false; - $br =& $this->addBlankElement('br'); + $br = $this->addBlankElement('br'); $br->attr['clear'] = 'Enum#left,all,right,none'; - $caption =& $this->addBlankElement('caption'); + $caption = $this->addBlankElement('caption'); $caption->attr['align'] = 'Enum#top,bottom,left,right'; - $div =& $this->addBlankElement('div'); + $div = $this->addBlankElement('div'); $div->attr['align'] = $align; - $dl =& $this->addBlankElement('dl'); + $dl = $this->addBlankElement('dl'); $dl->attr['compact'] = 'Bool#compact'; for ($i = 1; $i <= 6; $i++) { - $h =& $this->addBlankElement("h$i"); + $h = $this->addBlankElement("h$i"); $h->attr['align'] = $align; } - $hr =& $this->addBlankElement('hr'); + $hr = $this->addBlankElement('hr'); $hr->attr['align'] = $align; $hr->attr['noshade'] = 'Bool#noshade'; $hr->attr['size'] = 'Pixels'; $hr->attr['width'] = 'Length'; - $img =& $this->addBlankElement('img'); + $img = $this->addBlankElement('img'); $img->attr['align'] = 'Enum#top,middle,bottom,left,right'; $img->attr['border'] = 'Pixels'; $img->attr['hspace'] = 'Pixels'; @@ -90,43 +90,43 @@ class HTMLPurifier_HTMLModule_Legacy extends HTMLPurifier_HTMLModule // figure out this integer business - $li =& $this->addBlankElement('li'); + $li = $this->addBlankElement('li'); $li->attr['value'] = new HTMLPurifier_AttrDef_Integer(); $li->attr['type'] = 'Enum#s:1,i,I,a,A,disc,square,circle'; - $ol =& $this->addBlankElement('ol'); + $ol = $this->addBlankElement('ol'); $ol->attr['compact'] = 'Bool#compact'; $ol->attr['start'] = new HTMLPurifier_AttrDef_Integer(); $ol->attr['type'] = 'Enum#s:1,i,I,a,A'; - $p =& $this->addBlankElement('p'); + $p = $this->addBlankElement('p'); $p->attr['align'] = $align; - $pre =& $this->addBlankElement('pre'); + $pre = $this->addBlankElement('pre'); $pre->attr['width'] = 'Number'; // script omitted - $table =& $this->addBlankElement('table'); + $table = $this->addBlankElement('table'); $table->attr['align'] = 'Enum#left,center,right'; $table->attr['bgcolor'] = 'Color'; - $tr =& $this->addBlankElement('tr'); + $tr = $this->addBlankElement('tr'); $tr->attr['bgcolor'] = 'Color'; - $th =& $this->addBlankElement('th'); + $th = $this->addBlankElement('th'); $th->attr['bgcolor'] = 'Color'; $th->attr['height'] = 'Length'; $th->attr['nowrap'] = 'Bool#nowrap'; $th->attr['width'] = 'Length'; - $td =& $this->addBlankElement('td'); + $td = $this->addBlankElement('td'); $td->attr['bgcolor'] = 'Color'; $td->attr['height'] = 'Length'; $td->attr['nowrap'] = 'Bool#nowrap'; $td->attr['width'] = 'Length'; - $ul =& $this->addBlankElement('ul'); + $ul = $this->addBlankElement('ul'); $ul->attr['compact'] = 'Bool#compact'; $ul->attr['type'] = 'Enum#square,disc,circle'; diff --git a/library/HTMLPurifier/HTMLModule/Ruby.php b/library/HTMLPurifier/HTMLModule/Ruby.php index fc3caf7e..21ec79a2 100644 --- a/library/HTMLPurifier/HTMLModule/Ruby.php +++ b/library/HTMLPurifier/HTMLModule/Ruby.php @@ -15,9 +15,9 @@ class HTMLPurifier_HTMLModule_Ruby extends HTMLPurifier_HTMLModule 'Common'); $this->addElement('rbc', false, 'Required: rb', 'Common'); $this->addElement('rtc', false, 'Required: rt', 'Common'); - $rb =& $this->addElement('rb', false, 'Inline', 'Common'); + $rb = $this->addElement('rb', false, 'Inline', 'Common'); $rb->excludes = array('ruby' => true); - $rt =& $this->addElement('rt', false, 'Inline', 'Common', array('rbspan' => 'Number')); + $rt = $this->addElement('rt', false, 'Inline', 'Common', array('rbspan' => 'Number')); $rt->excludes = array('ruby' => true); $this->addElement('rp', false, 'Optional: #PCDATA', 'Common'); } diff --git a/library/HTMLPurifier/HTMLModule/Target.php b/library/HTMLPurifier/HTMLModule/Target.php index d96633cb..18203d04 100644 --- a/library/HTMLPurifier/HTMLModule/Target.php +++ b/library/HTMLPurifier/HTMLModule/Target.php @@ -11,7 +11,7 @@ class HTMLPurifier_HTMLModule_Target extends HTMLPurifier_HTMLModule public function __construct() { $elements = array('a'); foreach ($elements as $name) { - $e =& $this->addBlankElement($name); + $e = $this->addBlankElement($name); $e->attr = array( 'target' => new HTMLPurifier_AttrDef_HTML_FrameTarget() ); diff --git a/library/HTMLPurifier/HTMLModule/Text.php b/library/HTMLPurifier/HTMLModule/Text.php index 3acec4a6..4b13a80d 100644 --- a/library/HTMLPurifier/HTMLModule/Text.php +++ b/library/HTMLPurifier/HTMLModule/Text.php @@ -42,7 +42,7 @@ class HTMLPurifier_HTMLModule_Text extends HTMLPurifier_HTMLModule // Block Phrasal -------------------------------------------------- $this->addElement('address', 'Block', 'Inline', 'Common'); $this->addElement('blockquote', 'Block', 'Optional: Heading | Block | List', 'Common', array('cite' => 'URI') ); - $pre =& $this->addElement('pre', 'Block', 'Inline', 'Common'); + $pre = $this->addElement('pre', 'Block', 'Inline', 'Common'); $pre->excludes = $this->makeLookup( 'img', 'big', 'small', 'object', 'applet', 'font', 'basefont' ); $this->addElement('h1', 'Heading', 'Inline', 'Common'); diff --git a/library/HTMLPurifier/HTMLModule/Tidy.php b/library/HTMLPurifier/HTMLModule/Tidy.php index 81d1145f..1606ffc6 100644 --- a/library/HTMLPurifier/HTMLModule/Tidy.php +++ b/library/HTMLPurifier/HTMLModule/Tidy.php @@ -128,14 +128,16 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule if (isset($params['element'])) { $element = $params['element']; if (empty($this->info[$element])) { - $e =& $this->addBlankElement($element); + $e = $this->addBlankElement($element); } else { - $e =& $this->info[$element]; + $e = $this->info[$element]; } } else { $type = "info_$type"; - $e =& $this; + $e = $this; } + // PHP does some weird parsing when I do + // $e->$type[$attr], so I have to assign a ref. $f =& $e->$type; $f[$attr] = $fix; break; @@ -146,9 +148,9 @@ class HTMLPurifier_HTMLModule_Tidy extends HTMLPurifier_HTMLModule case 'content_model_type': $element = $params['element']; if (empty($this->info[$element])) { - $e =& $this->addBlankElement($element); + $e = $this->addBlankElement($element); } else { - $e =& $this->info[$element]; + $e = $this->info[$element]; } $e->$type = $fix; break; diff --git a/library/HTMLPurifier/Language.php b/library/HTMLPurifier/Language.php index 2404776d..d42075f3 100644 --- a/library/HTMLPurifier/Language.php +++ b/library/HTMLPurifier/Language.php @@ -1,5 +1,9 @@ config = $config; - $this->context =& $context; + $this->context = $context; } /** @@ -122,7 +126,7 @@ class HTMLPurifier_Language // could be introduced for all types of tokens. This // may need to be factored out into a dedicated class if (!empty($value->attr)) { - $stripped_token = $value->copy(); + $stripped_token = clone $value; $stripped_token->attr = array(); $subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token); } diff --git a/library/HTMLPurifier/LanguageFactory.php b/library/HTMLPurifier/LanguageFactory.php index 1348fb9d..ac820bb8 100644 --- a/library/HTMLPurifier/LanguageFactory.php +++ b/library/HTMLPurifier/LanguageFactory.php @@ -53,7 +53,7 @@ class HTMLPurifier_LanguageFactory * @param $prototype Optional prototype to overload sole instance with, * or bool true to reset to default factory. */ - public static function &instance($prototype = null) { + public static function instance($prototype = null) { static $instance = null; if ($prototype !== null) { $instance = $prototype; diff --git a/library/HTMLPurifier/Lexer.php b/library/HTMLPurifier/Lexer.php index 220ff149..01364f65 100644 --- a/library/HTMLPurifier/Lexer.php +++ b/library/HTMLPurifier/Lexer.php @@ -11,7 +11,8 @@ * * A lexer is HTML-oriented: it might work with XML, but it's not * recommended, as we adhere to a subset of the specification for optimization - * reasons. + * reasons. This might change in the future. Also, most tokenizers are not + * expected to handle DTDs or PIs. * * This class should not be directly instantiated, but you may use create() to * retrieve a default copy of the lexer. Being a supertype, this class @@ -20,7 +21,8 @@ * * @note The unit tests will instantiate this class for testing purposes, as * many of the utility functions require a class to be instantiated. - * Be careful when porting this class to PHP 5. + * This means that, even though this class is not runnable, it will + * not be declared abstract. * * @par * @@ -28,18 +30,14 @@ * We use tokens rather than create a DOM representation because DOM would: * * @par - * -# Require more processing power to create, - * -# Require recursion to iterate, - * -# Must be compatible with PHP 5's DOM (otherwise duplication), - * -# Has the entire document structure (html and body not needed), and - * -# Has unknown readability improvement. + * -# Require more processing and memory to create, + * -# Is not streamable, and + * -# Has the entire document structure (html and body not needed). * * @par - * What the last item means is that the functions for manipulating tokens are - * already fairly compact, and when well-commented, more abstraction may not - * be needed. - * - * @see HTMLPurifier_Token + * However, DOM is helpful in that it makes it easy to move around nodes + * without a lot of lookaheads to see when a tag is closed. This is a + * limitation of the token system and some workarounds would be nice. */ class HTMLPurifier_Lexer { @@ -49,22 +47,16 @@ class HTMLPurifier_Lexer /** * Retrieves or sets the default Lexer as a Prototype Factory. * - * Depending on what PHP version you are running, the abstract base - * Lexer class will determine which concrete Lexer is best for you: - * HTMLPurifier_Lexer_DirectLex for PHP 4, and HTMLPurifier_Lexer_DOMLex - * for PHP 5 and beyond. This general rule has a few exceptions to it - * involving special features that only DirectLex implements. + * By default HTMLPurifier_Lexer_DOMLex will be returned. There are + * a few exceptions involving special features that only DirectLex + * implements. * * @note The behavior of this class has changed, rather than accepting * a prototype object, it now accepts a configuration object. * To specify your own prototype, set %Core.LexerImpl to it. * This change in behavior de-singletonizes the lexer object. * - * @note In PHP4, it is possible to call this factory method from - * subclasses, such usage is not recommended and not - * forwards-compatible. - * - * @param $prototype Optional prototype lexer or configuration object + * @param $config Instance of HTMLPurifier_Config * @return Concrete lexer. */ public static function create($config) { @@ -96,8 +88,9 @@ class HTMLPurifier_Lexer break; } - if (version_compare(PHP_VERSION, "5", ">=") && // check for PHP5 - class_exists('DOMDocument')) { // check for DOM support + if (class_exists('DOMDocument')) { + // check for DOM support, because, surprisingly enough, + // it's *not* part of the core! $lexer = 'DOMLex'; } else { $lexer = 'DirectLex'; diff --git a/library/HTMLPurifier/Printer.php b/library/HTMLPurifier/Printer.php index 451f2ee4..680ffa1d 100644 --- a/library/HTMLPurifier/Printer.php +++ b/library/HTMLPurifier/Printer.php @@ -1,6 +1,7 @@ copy(); + $new_tag = clone $tag; $new_tag->name = $this->transform_to; return $new_tag; } @@ -81,7 +81,7 @@ class HTMLPurifier_TagTransform_Font extends HTMLPurifier_TagTransform $prepend_style; } - $new_tag = $tag->copy(); + $new_tag = clone $tag; $new_tag->name = $this->transform_to; $new_tag->attr = $attr; diff --git a/library/HTMLPurifier/TagTransform/Simple.php b/library/HTMLPurifier/TagTransform/Simple.php index bf8d2a3c..f68c6c28 100644 --- a/library/HTMLPurifier/TagTransform/Simple.php +++ b/library/HTMLPurifier/TagTransform/Simple.php @@ -20,7 +20,7 @@ class HTMLPurifier_TagTransform_Simple extends HTMLPurifier_TagTransform } public function transform($tag, $config, $context) { - $new_tag = $tag->copy(); + $new_tag = clone $tag; $new_tag->name = $this->transform_to; if (!is_null($this->style) && ($new_tag instanceof HTMLPurifier_Token_Start || $new_tag instanceof HTMLPurifier_Token_Empty) diff --git a/library/HTMLPurifier/Token.php b/library/HTMLPurifier/Token.php index 788b06cb..fd2ba53f 100644 --- a/library/HTMLPurifier/Token.php +++ b/library/HTMLPurifier/Token.php @@ -14,14 +14,6 @@ class HTMLPurifier_Token { */ public $armor = array(); - /** - * Copies the tag into a new one (clone substitute). - * @return Copied token - */ - public function copy() { - return unserialize(serialize($this)); - } - public function __get($n) { if ($n === 'type') { trigger_error('Deprecated type property called; use instanceof', E_USER_NOTICE); diff --git a/library/HTMLPurifier/TokenFactory.php b/library/HTMLPurifier/TokenFactory.php index adf12290..bff693f4 100644 --- a/library/HTMLPurifier/TokenFactory.php +++ b/library/HTMLPurifier/TokenFactory.php @@ -1,15 +1,15 @@ parse('http://example.com'); $this->config->set('URI', 'DefinitionID', 'HTMLPurifier_AttrDef_URITest->testURIDefinitionValidation'); - $uri_def =& $this->config->getDefinition('URI'); - // overload with mock + generate_mock_once('HTMLPurifier_URIDefinition'); $uri_def = new HTMLPurifier_URIDefinitionMock(); $uri_def->expectOnce('filter', array($uri, '*', '*')); $uri_def->setReturnValue('filter', true, array($uri, '*', '*')); $uri_def->setup = true; + + // Since definitions are no longer passed by reference, we need + // to muck around with the cache to insert our mock. This is + // technically a little bad, since the cache shouldn't change + // behavior, but I don't feel too good about letting users + // overload entire definitions. + generate_mock_once('HTMLPurifier_DefinitionCache'); + $cache_mock = new HTMLPurifier_DefinitionCacheMock(); + $cache_mock->setReturnValue('get', $uri_def); + + generate_mock_once('HTMLPurifier_DefinitionCacheFactory'); + $factory_mock = new HTMLPurifier_DefinitionCacheFactoryMock(); + $old = HTMLPurifier_DefinitionCacheFactory::instance(); + HTMLPurifier_DefinitionCacheFactory::instance($factory_mock); + $factory_mock->setReturnValue('create', $cache_mock); + $this->assertDef('http://example.com'); + + HTMLPurifier_DefinitionCacheFactory::instance($old); } /* diff --git a/tests/HTMLPurifier/AttrValidator_ErrorsTest.php b/tests/HTMLPurifier/AttrValidator_ErrorsTest.php index f8b83715..d3242c06 100644 --- a/tests/HTMLPurifier/AttrValidator_ErrorsTest.php +++ b/tests/HTMLPurifier/AttrValidator_ErrorsTest.php @@ -11,7 +11,7 @@ class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness function testAttributesTransformedGlobalPre() { $this->config->set('HTML', 'DefinitionID', 'HTMLPurifier_AttrValidator_ErrorsTest::testAttributesTransformedGlobalPre'); - $def =& $this->config->getHTMLDefinition(true); + $def = $this->config->getHTMLDefinition(true); generate_mock_once('HTMLPurifier_AttrTransform'); $transform = new HTMLPurifier_AttrTransformMock(); $input = array('original' => 'value'); diff --git a/tests/HTMLPurifier/ConfigTest.php b/tests/HTMLPurifier/ConfigTest.php index edb13b3e..8bc759d7 100644 --- a/tests/HTMLPurifier/ConfigTest.php +++ b/tests/HTMLPurifier/ConfigTest.php @@ -219,27 +219,25 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $def = $config->getCSSDefinition(); $this->assertIsA($def, 'HTMLPurifier_CSSDefinition'); - $def =& $config->getHTMLDefinition(); - $def2 =& $config->getHTMLDefinition(); + $def = $config->getHTMLDefinition(); + $def2 = $config->getHTMLDefinition(); $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition'); - $this->assertReference($def, $def2); + $this->assertSame($def, $def2); $this->assertTrue($def->setup); - // test re-calculation if HTML changes - unset($def, $def2); - $def2 = $config->getHTMLDefinition(); // forcibly de-reference + $old_def = clone $def2; $config->set('HTML', 'Doctype', 'HTML 4.01 Transitional'); $def = $config->getHTMLDefinition(); $this->assertIsA($def, 'HTMLPurifier_HTMLDefinition'); - $this->assertNotEqual($def, $def2); + $this->assertNotEqual($def, $old_def); $this->assertTrue($def->setup); // test retrieval of raw definition $config->set('HTML', 'DefinitionID', 'HTMLPurifier_ConfigTest->test_getHTMLDefinition()'); $config->set('HTML', 'DefinitionRev', 3); - $def =& $config->getHTMLDefinition(true); - $this->assertNotEqual($def, $def2); + $def = $config->getHTMLDefinition(true); + $this->assertNotEqual($def, $old_def); $this->assertEqual(false, $def->setup); // auto initialization @@ -250,8 +248,8 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness function test_getHTMLDefinition_rawError() { $config = HTMLPurifier_Config::createDefault(); - $this->expectError('Cannot retrieve raw version without specifying %HTML.DefinitionID'); - $def =& $config->getHTMLDefinition(true); + $this->expectException(new HTMLPurifier_Exception('Cannot retrieve raw version without specifying %HTML.DefinitionID')); + $def = $config->getHTMLDefinition(true); } function test_getCSSDefinition() { @@ -265,7 +263,7 @@ class HTMLPurifier_ConfigTest extends HTMLPurifier_Harness $this->schema->add('Cache', 'DefinitionImpl', null, 'string', true); $this->schema->addNamespace('Crust', 'Krusty Krabs'); $config = new HTMLPurifier_Config($this->schema); - $this->expectError("Definition of Crust type not supported"); + $this->expectException(new HTMLPurifier_Exception("Definition of Crust type not supported")); $config->getDefinition('Crust'); } diff --git a/tests/HTMLPurifier/DoctypeRegistryTest.php b/tests/HTMLPurifier/DoctypeRegistryTest.php index 78b8a7fb..ac68b927 100644 --- a/tests/HTMLPurifier/DoctypeRegistryTest.php +++ b/tests/HTMLPurifier/DoctypeRegistryTest.php @@ -7,7 +7,7 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness $registry = new HTMLPurifier_DoctypeRegistry(); - $d =& $registry->register( + $d = $registry->register( $name = 'XHTML 1.0 Transitional', $xml = true, $modules = array('module-one', 'module-two'), @@ -18,10 +18,10 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness $d2 = new HTMLPurifier_Doctype($name, $xml, $modules, $tidyModules, $aliases); $this->assertIdentical($d, $d2); - $this->assertReference($d, $registry->get('XHTML 1.0 Transitional')); + $this->assertSame($d, $registry->get('XHTML 1.0 Transitional')); // test shorthand - $d =& $registry->register( + $d = $registry->register( $name = 'XHTML 1.0 Strict', true, 'module', 'Tidy', 'X10S' ); $d2 = new HTMLPurifier_Doctype($name, true, array('module'), array('Tidy'), array('X10S')); @@ -49,26 +49,26 @@ class HTMLPurifier_DoctypeRegistryTest extends HTMLPurifier_Harness $registry = new HTMLPurifier_DoctypeRegistry(); - $d1 =& $registry->register('Doc1', true, array(), array(), array('1')); + $d1 = $registry->register('Doc1', true, array(), array(), array('1')); - $this->assertReference($d1, $registry->get('Doc1')); - $this->assertReference($d1, $registry->get('1')); + $this->assertSame($d1, $registry->get('Doc1')); + $this->assertSame($d1, $registry->get('1')); - $d2 =& $registry->register('Doc2', true, array(), array(), array('2')); + $d2 = $registry->register('Doc2', true, array(), array(), array('2')); - $this->assertReference($d2, $registry->get('Doc2')); - $this->assertReference($d2, $registry->get('2')); + $this->assertSame($d2, $registry->get('Doc2')); + $this->assertSame($d2, $registry->get('2')); - $d3 =& $registry->register('1', true, array(), array(), array()); + $d3 = $registry->register('1', true, array(), array(), array()); // literal name overrides alias - $this->assertReference($d3, $registry->get('1')); + $this->assertSame($d3, $registry->get('1')); - $d4 =& $registry->register('One', true, array(), array(), array('1')); + $d4 = $registry->register('One', true, array(), array(), array('1')); - $this->assertReference($d4, $registry->get('One')); + $this->assertSame($d4, $registry->get('One')); // still it overrides - $this->assertReference($d3, $registry->get('1')); + $this->assertSame($d3, $registry->get('1')); } diff --git a/tests/HTMLPurifier/HTMLDefinitionTest.php b/tests/HTMLPurifier/HTMLDefinitionTest.php index 64e9e1a3..42010f58 100644 --- a/tests/HTMLPurifier/HTMLDefinitionTest.php +++ b/tests/HTMLPurifier/HTMLDefinitionTest.php @@ -75,7 +75,7 @@ a[href|title] $config = HTMLPurifier_Config::create(array( 'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute' )); - $def =& $config->getHTMLDefinition(true); + $def = $config->getHTMLDefinition(true); $def->addAttribute('span', 'custom', 'Enum#attribute'); $purifier = new HTMLPurifier($config); @@ -90,7 +90,7 @@ a[href|title] $config = HTMLPurifier_Config::create(array( 'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addAttribute_multiple' )); - $def =& $config->getHTMLDefinition(true); + $def = $config->getHTMLDefinition(true); $def->addAttribute('span', 'custom', 'Enum#attribute'); $def->addAttribute('span', 'foo', 'Text'); @@ -106,7 +106,7 @@ a[href|title] $config = HTMLPurifier_Config::create(array( 'HTML.DefinitionID' => 'HTMLPurifier_HTMLDefinitionTest->test_addElement' )); - $def =& $config->getHTMLDefinition(true); + $def = $config->getHTMLDefinition(true); $def->addElement('marquee', 'Inline', 'Inline', 'Common', array('width' => 'Length')); $purifier = new HTMLPurifier($config); diff --git a/tests/HTMLPurifier/HTMLModule/TidyTest.php b/tests/HTMLPurifier/HTMLModule/TidyTest.php index b850962d..62157660 100644 --- a/tests/HTMLPurifier/HTMLModule/TidyTest.php +++ b/tests/HTMLPurifier/HTMLModule/TidyTest.php @@ -206,7 +206,7 @@ class HTMLPurifier_HTMLModule_TidyTest extends HTMLPurifier_Harness )); $module2 = new HTMLPurifier_HTMLModule_Tidy(); - $e =& $module2->addBlankElement('element'); + $e = $module2->addBlankElement('element'); $e->attr_transform_pre['attr'] = $attr; $e->attr_transform_post['attr'] = $attr_post; $e->child = $child; diff --git a/tests/HTMLPurifier/HTMLModuleTest.php b/tests/HTMLPurifier/HTMLModuleTest.php index ac88df0e..f1da074e 100644 --- a/tests/HTMLPurifier/HTMLModuleTest.php +++ b/tests/HTMLPurifier/HTMLModuleTest.php @@ -18,7 +18,7 @@ class HTMLPurifier_HTMLModuleTest extends HTMLPurifier_Harness function test_addElement() { $module = new HTMLPurifier_HTMLModule(); - $def =& $module->addElement( + $def = $module->addElement( 'a', 'Inline', 'Optional: #PCDATA', array('Common'), array( 'href' => 'URI' @@ -107,7 +107,7 @@ class HTMLPurifier_HTMLModuleTest extends HTMLPurifier_Harness function test_addBlankElement() { $module = new HTMLPurifier_HTMLModule(); - $def =& $module->addBlankElement('a'); + $def = $module->addBlankElement('a'); $def2 = new HTMLPurifier_ElementDef(); $def2->standalone = false; diff --git a/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php b/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php index 4c4c9de7..98b1615d 100644 --- a/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php +++ b/tests/HTMLPurifier/Strategy/RemoveForeignElementsTest.php @@ -83,7 +83,7 @@ alert(<b>bold</b>); $this->config->set('HTML', 'DefinitionID', 'HTMLPurifier_Strategy_RemoveForeignElementsTest'. '->testRequiredAttributesTestNotPerformedOnEndTag'); - $def =& $this->config->getHTMLDefinition(true); + $def = $this->config->getHTMLDefinition(true); $def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text')); $this->assertResult('$uri = $config->getDefinition('URI'); $uri->addFilter(new HTMLPurifier_URIFilter_NameOfFilter());@@ -177,7 +177,7 @@ $uri->addFilter(new HTMLPurifier_URIFilter_NameOfFilter());NameOfFilter', false, 'bool', 'What your filter does.' ); -$uri =& $config->getDefinition('URI', true); +$uri = $config->getDefinition('URI', true); $uri->registerFilter(new HTMLPurifier_URIFilter_NameOfFilter());