0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-12-22 08:21:52 +00:00

Fix some PHP 8.2 deprecations (#319)

* Define HTMLPurifier_Lexer::$_entity_parser property

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_URIFilterHarness::$filter property

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_AttrTransform_NameSync::$idDef property

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_AttrTransform_NameSyncTest::$accumulator property

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_AttrValidator_ErrorsTest::$language property

This fixes a PHP 8.2 deprecation.

* Define HTMLPurifier_ChildDef_List::$whitespace property

This fixes a PHP 8.2 deprecation.

* Do not modify incoming tokens in RemoveSpansWithoutAttributes

Previously the undefined property `->markForDeletion` was added to the incoming
tokens. This causes a deprecation in PHP 8.2. Fix this by storing to-be-deleted
tokens inside SplObjectStorage. In PHP 8 a WeakMap would be preferable, as that
prevents leaks if `handleEnd` is never called for the token.
This commit is contained in:
Tim Düsterhus 2022-06-10 22:30:01 +02:00 committed by GitHub
parent 38296c603b
commit 1db36fb09d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 2 deletions

View File

@ -8,6 +8,11 @@
class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform class HTMLPurifier_AttrTransform_NameSync extends HTMLPurifier_AttrTransform
{ {
/**
* @type HTMLPurifier_AttrDef_HTML_ID
*/
public $idDef;
public function __construct() public function __construct()
{ {
$this->idDef = new HTMLPurifier_AttrDef_HTML_ID(); $this->idDef = new HTMLPurifier_AttrDef_HTML_ID();

View File

@ -22,6 +22,8 @@ class HTMLPurifier_ChildDef_List extends HTMLPurifier_ChildDef
// XXX: This whole business with 'wrap' is all a bit unsatisfactory // XXX: This whole business with 'wrap' is all a bit unsatisfactory
public $elements = array('li' => true, 'ul' => true, 'ol' => true); public $elements = array('li' => true, 'ul' => true, 'ol' => true);
public $whitespace;
/** /**
* @param array $children * @param array $children
* @param HTMLPurifier_Config $config * @param HTMLPurifier_Config $config

View File

@ -31,6 +31,16 @@ class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_In
*/ */
private $context; private $context;
/**
* @type SplObjectStorage
*/
private $markForDeletion;
public function __construct()
{
$this->markForDeletion = new SplObjectStorage();
}
public function prepare($config, $context) public function prepare($config, $context)
{ {
$this->attrValidator = new HTMLPurifier_AttrValidator(); $this->attrValidator = new HTMLPurifier_AttrValidator();
@ -64,7 +74,7 @@ class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_In
if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') { if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') {
// Mark closing span tag for deletion // Mark closing span tag for deletion
$current->markForDeletion = true; $this->markForDeletion->attach($current);
// Delete open span tag // Delete open span tag
$token = false; $token = false;
} }
@ -75,7 +85,8 @@ class HTMLPurifier_Injector_RemoveSpansWithoutAttributes extends HTMLPurifier_In
*/ */
public function handleEnd(&$token) public function handleEnd(&$token)
{ {
if ($token->markForDeletion) { if ($this->markForDeletion->contains($token)) {
$this->markForDeletion->detach($token);
$token = false; $token = false;
} }
} }

View File

@ -48,6 +48,11 @@ class HTMLPurifier_Lexer
*/ */
public $tracksLineNumbers = false; public $tracksLineNumbers = false;
/**
* @type HTMLPurifier_EntityParser
*/
private $_entity_parser;
// -- STATIC ---------------------------------------------------------- // -- STATIC ----------------------------------------------------------
/** /**

View File

@ -3,6 +3,11 @@
class HTMLPurifier_AttrTransform_NameSyncTest extends HTMLPurifier_AttrTransformHarness class HTMLPurifier_AttrTransform_NameSyncTest extends HTMLPurifier_AttrTransformHarness
{ {
/**
* @type HTMLPurifier_IDAccumulator
*/
public $accumulator;
public function setUp() public function setUp()
{ {
parent::setUp(); parent::setUp();

View File

@ -3,6 +3,11 @@
class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness class HTMLPurifier_AttrValidator_ErrorsTest extends HTMLPurifier_ErrorsHarness
{ {
/**
* @type HTMLPurifier_Language
*/
public $language;
public function setup() public function setup()
{ {
parent::setup(); parent::setup();

View File

@ -3,6 +3,11 @@
class HTMLPurifier_URIFilterHarness extends HTMLPurifier_URIHarness class HTMLPurifier_URIFilterHarness extends HTMLPurifier_URIHarness
{ {
/**
* @type HTMLPurifier_URIFilter
*/
public $filter;
protected function assertFiltering($uri, $expect_uri = true) protected function assertFiltering($uri, $expect_uri = true)
{ {
$this->prepareURI($uri, $expect_uri); $this->prepareURI($uri, $expect_uri);