Skip to content

Commit 81ce8e0

Browse files
committed
Fix PHP 8.5 deprecations in URISchemeRegistry and RemoveSpansWithoutAttributes
URISchemeRegistry::getScheme() can receive null when a URI has no scheme (relative URIs). PHP 8.5 deprecates null as an array offset — add an early return for null scheme. SplObjectStorage::attach(), contains(), detach() are deprecated in PHP 8.5 in favour of offsetSet(), offsetExists(), offsetUnset(). Update RemoveSpansWithoutAttributes to use the new method names.
1 parent 79794f1 commit 81ce8e0

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

library/HTMLPurifier/Injector/RemoveSpansWithoutAttributes.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public function handleElement(&$token)
7474

7575
if ($current instanceof HTMLPurifier_Token_End && $current->name === 'span') {
7676
// Mark closing span tag for deletion
77-
$this->markForDeletion->attach($current);
77+
// PHP 8.5: SplObjectStorage::attach() deprecated in favour of offsetSet()
78+
$this->markForDeletion->offsetSet($current);
7879
// Delete open span tag
7980
$token = false;
8081
}
@@ -85,8 +86,10 @@ public function handleElement(&$token)
8586
*/
8687
public function handleEnd(&$token)
8788
{
88-
if ($this->markForDeletion->contains($token)) {
89-
$this->markForDeletion->detach($token);
89+
// PHP 8.5: SplObjectStorage::contains()/detach() deprecated in favour of
90+
// offsetExists()/offsetUnset()
91+
if ($this->markForDeletion->offsetExists($token)) {
92+
$this->markForDeletion->offsetUnset($token);
9093
$token = false;
9194
}
9295
}

library/HTMLPurifier/URISchemeRegistry.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ public function getScheme($scheme, $config, $context)
4444
$config = HTMLPurifier_Config::createDefault();
4545
}
4646

47+
// PHP 8.5: null as array offset is deprecated; URIs without a scheme
48+
// (e.g. relative URIs) produce a null $scheme — bail out early.
49+
if ($scheme === null) {
50+
return;
51+
}
52+
4753
// important, otherwise attacker could include arbitrary file
4854
$allowed_schemes = $config->get('URI.AllowedSchemes');
4955
if (!$config->get('URI.OverrideAllowedSchemes') &&

0 commit comments

Comments
 (0)