Skip to content

Commit ff005f6

Browse files
authored
feat: PHP 8.4 support (#441)
1 parent c2bc354 commit ff005f6

26 files changed

+48
-81
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
strategy:
1111
fail-fast: true
1212
matrix:
13-
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
13+
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
1414

1515
name: PHP ${{ matrix.php }}
1616

configdoc/generate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
if (version_compare(PHP_VERSION, '5.2', '<')) exit('PHP 5.2+ required.');
19-
error_reporting(E_ALL | E_STRICT);
19+
error_reporting(E_ALL);
2020

2121
// load dual-libraries
2222
require_once dirname(__FILE__) . '/../extras/HTMLPurifierExtras.auto.php';

library/HTMLPurifier/AttrDef/HTML/LinkTypes.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,7 @@ public function __construct($name)
2525
'rev' => 'AllowedRev'
2626
);
2727
if (!isset($configLookup[$name])) {
28-
trigger_error(
29-
'Unrecognized attribute name for link ' .
30-
'relationship.',
31-
E_USER_ERROR
32-
);
33-
return;
28+
throw new Exception('Unrecognized attribute name for link relationship.');
3429
}
3530
$this->name = $configLookup[$name];
3631
}

library/HTMLPurifier/AttrTypes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function get($type)
7777
}
7878

7979
if (!isset($this->info[$type])) {
80-
trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
80+
throw new Exception('Cannot retrieve undefined attribute type ' . $type);
8181
return;
8282
}
8383
return $this->info[$type]->make($string);

library/HTMLPurifier/Config.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,11 @@ protected function triggerError($msg, $no)
898898
break;
899899
}
900900
}
901-
trigger_error($msg . $extra, $no);
901+
if ($no == E_USER_ERROR) {
902+
throw new Exception($msg . $extra);
903+
} else {
904+
trigger_error($msg . $extra, $no);
905+
}
902906
}
903907

904908
/**

library/HTMLPurifier/ConfigSchema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function makeFromSerial()
7272
$r = unserialize($contents);
7373
if (!$r) {
7474
$hash = sha1($contents);
75-
trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR);
75+
throw new Exception("Unserialization of configuration schema failed, sha1 of file was $hash");
7676
}
7777
return $r;
7878
}

library/HTMLPurifier/ContentSets.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,11 @@ public function getChildDef($def, $module)
142142
if ($return !== false) {
143143
return $return;
144144
}
145-
// error-out
146-
trigger_error(
145+
146+
throw new Exception(
147147
'Could not determine which ChildDef class to instantiate',
148148
E_USER_ERROR
149149
);
150-
return false;
151150
}
152151

153152
/**

library/HTMLPurifier/Context.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ class HTMLPurifier_Context
2424
public function register($name, &$ref)
2525
{
2626
if (array_key_exists($name, $this->_storage)) {
27-
trigger_error(
28-
"Name $name produces collision, cannot re-register",
29-
E_USER_ERROR
30-
);
31-
return;
27+
throw new Exception("Name $name produces collision, cannot re-register");
3228
}
3329
$this->_storage[$name] =& $ref;
3430
}
@@ -43,10 +39,7 @@ public function &get($name, $ignore_error = false)
4339
{
4440
if (!array_key_exists($name, $this->_storage)) {
4541
if (!$ignore_error) {
46-
trigger_error(
47-
"Attempted to retrieve non-existent variable $name",
48-
E_USER_ERROR
49-
);
42+
throw new Exception("Attempted to retrieve non-existent variable $name");
5043
}
5144
$var = null; // so we can return by reference
5245
return $var;
@@ -61,11 +54,7 @@ public function &get($name, $ignore_error = false)
6154
public function destroy($name)
6255
{
6356
if (!array_key_exists($name, $this->_storage)) {
64-
trigger_error(
65-
"Attempted to destroy non-existent variable $name",
66-
E_USER_ERROR
67-
);
68-
return;
57+
throw new Exception("Attempted to destroy non-existent variable $name");
6958
}
7059
unset($this->_storage[$name]);
7160
}

library/HTMLPurifier/DoctypeRegistry.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function get($doctype)
8686
$doctype = $this->aliases[$doctype];
8787
}
8888
if (!isset($this->doctypes[$doctype])) {
89-
trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
89+
throw new Exception('Doctype ' . htmlspecialchars($doctype) . ' does not exist');
9090
$anon = new HTMLPurifier_Doctype($doctype);
9191
return $anon;
9292
}

library/HTMLPurifier/Encoder.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class HTMLPurifier_Encoder
1212
*/
1313
private function __construct()
1414
{
15-
trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
15+
throw new Exception('Cannot instantiate encoder, call methods statically');
1616
}
1717

1818
/**
@@ -390,7 +390,7 @@ public static function convertToUTF8($str, $config, $context)
390390
$str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str);
391391
if ($str === false) {
392392
// $encoding is not a valid encoding
393-
trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
393+
throw new Exception('Invalid encoding ' . $encoding);
394394
return '';
395395
}
396396
// If the string is bjorked by Shift_JIS or a similar encoding
@@ -404,12 +404,11 @@ public static function convertToUTF8($str, $config, $context)
404404
}
405405
$bug = HTMLPurifier_Encoder::testIconvTruncateBug();
406406
if ($bug == self::ICONV_OK) {
407-
trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
407+
throw new Exception('Encoding not supported, please install iconv');
408408
} else {
409-
trigger_error(
409+
throw new Exception(
410410
'You have a buggy version of iconv, see https://bugs.php.net/bug.php?id=48147 ' .
411-
'and http://sourceware.org/bugzilla/show_bug.cgi?id=13541',
412-
E_USER_ERROR
411+
'and http://sourceware.org/bugzilla/show_bug.cgi?id=13541'
413412
);
414413
}
415414
}
@@ -454,7 +453,7 @@ public static function convertFromUTF8($str, $config, $context)
454453
$str = mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8');
455454
return $str;
456455
}
457-
trigger_error('Encoding not supported', E_USER_ERROR);
456+
throw new Exception('Encoding not supported');
458457
// You might be tempted to assume that the ASCII representation
459458
// might be OK, however, this is *not* universally true over all
460459
// encodings. So we take the conservative route here, rather
@@ -545,10 +544,9 @@ public static function testIconvTruncateBug()
545544
} elseif (($c = strlen($r)) < 9000) {
546545
$code = self::ICONV_TRUNCATES;
547546
} elseif ($c > 9000) {
548-
trigger_error(
547+
throw new Exception(
549548
'Your copy of iconv is extremely buggy. Please notify HTML Purifier maintainers: ' .
550-
'include your iconv version as per phpversion()',
551-
E_USER_ERROR
549+
'include your iconv version as per phpversion()'
552550
);
553551
} else {
554552
$code = self::ICONV_OK;

0 commit comments

Comments
 (0)