Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']

name: PHP ${{ matrix.php }}

Expand Down
2 changes: 1 addition & 1 deletion configdoc/generate.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

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

// load dual-libraries
require_once dirname(__FILE__) . '/../extras/HTMLPurifierExtras.auto.php';
Expand Down
7 changes: 1 addition & 6 deletions library/HTMLPurifier/AttrDef/HTML/LinkTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ public function __construct($name)
'rev' => 'AllowedRev'
);
if (!isset($configLookup[$name])) {
trigger_error(
'Unrecognized attribute name for link ' .
'relationship.',
E_USER_ERROR
);
return;
throw new Exception('Unrecognized attribute name for link relationship.');
}
$this->name = $configLookup[$name];
}
Expand Down
2 changes: 1 addition & 1 deletion library/HTMLPurifier/AttrTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function get($type)
}

if (!isset($this->info[$type])) {
trigger_error('Cannot retrieve undefined attribute type ' . $type, E_USER_ERROR);
throw new Exception('Cannot retrieve undefined attribute type ' . $type);
return;
}
return $this->info[$type]->make($string);
Expand Down
6 changes: 5 additions & 1 deletion library/HTMLPurifier/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,11 @@ protected function triggerError($msg, $no)
break;
}
}
trigger_error($msg . $extra, $no);
if ($no == E_USER_ERROR) {
throw new Exception($msg . $extra);
} else {
trigger_error($msg . $extra, $no);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/HTMLPurifier/ConfigSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static function makeFromSerial()
$r = unserialize($contents);
if (!$r) {
$hash = sha1($contents);
trigger_error("Unserialization of configuration schema failed, sha1 of file was $hash", E_USER_ERROR);
throw new Exception("Unserialization of configuration schema failed, sha1 of file was $hash");
}
return $r;
}
Expand Down
5 changes: 2 additions & 3 deletions library/HTMLPurifier/ContentSets.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,11 @@ public function getChildDef($def, $module)
if ($return !== false) {
return $return;
}
// error-out
trigger_error(

throw new Exception(
'Could not determine which ChildDef class to instantiate',
E_USER_ERROR
);
return false;
}

/**
Expand Down
17 changes: 3 additions & 14 deletions library/HTMLPurifier/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ class HTMLPurifier_Context
public function register($name, &$ref)
{
if (array_key_exists($name, $this->_storage)) {
trigger_error(
"Name $name produces collision, cannot re-register",
E_USER_ERROR
);
return;
throw new Exception("Name $name produces collision, cannot re-register");
}
$this->_storage[$name] =& $ref;
}
Expand All @@ -43,10 +39,7 @@ public function &get($name, $ignore_error = false)
{
if (!array_key_exists($name, $this->_storage)) {
if (!$ignore_error) {
trigger_error(
"Attempted to retrieve non-existent variable $name",
E_USER_ERROR
);
throw new Exception("Attempted to retrieve non-existent variable $name");
}
$var = null; // so we can return by reference
return $var;
Expand All @@ -61,11 +54,7 @@ public function &get($name, $ignore_error = false)
public function destroy($name)
{
if (!array_key_exists($name, $this->_storage)) {
trigger_error(
"Attempted to destroy non-existent variable $name",
E_USER_ERROR
);
return;
throw new Exception("Attempted to destroy non-existent variable $name");
}
unset($this->_storage[$name]);
}
Expand Down
2 changes: 1 addition & 1 deletion library/HTMLPurifier/DoctypeRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function get($doctype)
$doctype = $this->aliases[$doctype];
}
if (!isset($this->doctypes[$doctype])) {
trigger_error('Doctype ' . htmlspecialchars($doctype) . ' does not exist', E_USER_ERROR);
throw new Exception('Doctype ' . htmlspecialchars($doctype) . ' does not exist');
$anon = new HTMLPurifier_Doctype($doctype);
return $anon;
}
Expand Down
18 changes: 8 additions & 10 deletions library/HTMLPurifier/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HTMLPurifier_Encoder
*/
private function __construct()
{
trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
throw new Exception('Cannot instantiate encoder, call methods statically');
}

/**
Expand Down Expand Up @@ -390,7 +390,7 @@ public static function convertToUTF8($str, $config, $context)
$str = self::unsafeIconv($encoding, 'utf-8//IGNORE', $str);
if ($str === false) {
// $encoding is not a valid encoding
trigger_error('Invalid encoding ' . $encoding, E_USER_ERROR);
throw new Exception('Invalid encoding ' . $encoding);
return '';
}
// If the string is bjorked by Shift_JIS or a similar encoding
Expand All @@ -404,12 +404,11 @@ public static function convertToUTF8($str, $config, $context)
}
$bug = HTMLPurifier_Encoder::testIconvTruncateBug();
if ($bug == self::ICONV_OK) {
trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
throw new Exception('Encoding not supported, please install iconv');
} else {
trigger_error(
throw new Exception(
'You have a buggy version of iconv, see https://bugs.php.net/bug.php?id=48147 ' .
'and http://sourceware.org/bugzilla/show_bug.cgi?id=13541',
E_USER_ERROR
'and http://sourceware.org/bugzilla/show_bug.cgi?id=13541'
);
}
}
Expand Down Expand Up @@ -454,7 +453,7 @@ public static function convertFromUTF8($str, $config, $context)
$str = mb_convert_encoding($str, 'ISO-8859-1', 'UTF-8');
return $str;
}
trigger_error('Encoding not supported', E_USER_ERROR);
throw new Exception('Encoding not supported');
// You might be tempted to assume that the ASCII representation
// might be OK, however, this is *not* universally true over all
// encodings. So we take the conservative route here, rather
Expand Down Expand Up @@ -545,10 +544,9 @@ public static function testIconvTruncateBug()
} elseif (($c = strlen($r)) < 9000) {
$code = self::ICONV_TRUNCATES;
} elseif ($c > 9000) {
trigger_error(
throw new Exception(
'Your copy of iconv is extremely buggy. Please notify HTML Purifier maintainers: ' .
'include your iconv version as per phpversion()',
E_USER_ERROR
'include your iconv version as per phpversion()'
);
} else {
$code = self::ICONV_OK;
Expand Down
11 changes: 3 additions & 8 deletions library/HTMLPurifier/HTMLDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,8 @@ protected function setupConfigStuff($config)
if (isset($this->info_content_sets['Block'][$block_wrapper])) {
$this->info_block_wrapper = $block_wrapper;
} else {
trigger_error(
'Cannot use non-block element as block wrapper',
E_USER_ERROR
throw new Exception(
'Cannot use non-block element as block wrapper'
);
}

Expand All @@ -276,11 +275,7 @@ protected function setupConfigStuff($config)
$this->info_parent = $parent;
$this->info_parent_def = $def;
} else {
trigger_error(
'Cannot use unrecognized element as parent',
E_USER_ERROR
);
$this->info_parent_def = $this->manager->getElement($this->info_parent, true);
throw new Exception('Cannot use unrecognized element as parent');
}

// support template text
Expand Down
8 changes: 3 additions & 5 deletions library/HTMLPurifier/HTMLModule/Tidy.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ public function makeFixesForLevel($fixes)
return;
}
if (!isset($this->fixesForLevel[$this->defaultLevel])) {
trigger_error(
'Default level ' . $this->defaultLevel . ' does not exist',
E_USER_ERROR
throw new Exception(
'Default level ' . $this->defaultLevel . ' does not exist'
);
return;
}
Expand Down Expand Up @@ -162,8 +161,7 @@ public function populate($fixes)
$e->$type = $fix;
break;
default:
trigger_error("Fix type $type not supported", E_USER_ERROR);
break;
throw new Exception("Fix type $type not supported");
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions library/HTMLPurifier/HTMLModuleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,7 @@ public function registerModule($module, $overload = false)
if (!$ok) {
$module = $original_module;
if (!class_exists($module)) {
trigger_error(
$original_module . ' module does not exist',
E_USER_ERROR
);
return;
throw new Exception($original_module . ' module does not exist');
}
}
$module = new $module();
Expand Down
8 changes: 1 addition & 7 deletions library/HTMLPurifier/LanguageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,8 @@ public function loadLanguage($code)

// infinite recursion guard
if (isset($languages_seen[$code])) {
trigger_error(
'Circular fallback reference in language ' .
$code,
E_USER_ERROR
);
$fallback = 'en';
throw new Exception('Circular fallback reference in language ' . $code);
}
$language_seen[$code] = true;

// load the fallback recursively
$this->loadLanguage($fallback);
Expand Down
2 changes: 1 addition & 1 deletion library/HTMLPurifier/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public function parseData($string, $is_attr, $config)
*/
public function tokenizeHTML($string, $config, $context)
{
trigger_error('Call to abstract class', E_USER_ERROR);
throw new Exception('Call to abstract class');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion library/HTMLPurifier/URIScheme/data.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function doValidate(&$uri, $config, $context)
}
$image_code = $info[2];
} else {
trigger_error("could not find exif_imagetype or getimagesize functions", E_USER_ERROR);
throw new Exception("could not find exif_imagetype or getimagesize functions");
}
$real_content_type = image_type_to_mime_type($image_code);
if ($real_content_type != $content_type) {
Expand Down
2 changes: 1 addition & 1 deletion tests/HTMLPurifier/AttrTypesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function test_get()
new HTMLPurifier_AttrDef_Text()
);

$this->expectError('Cannot retrieve undefined attribute type foobar');
$this->expectException(new Exception('Cannot retrieve undefined attribute type foobar'));
$types->get('foobar');

$this->assertIdentical(
Expand Down
2 changes: 1 addition & 1 deletion tests/HTMLPurifier/ChildDef/StrictBlockquoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testAlternateWrapper()

public function testError()
{
$this->expectError('Cannot use non-block element as block wrapper');
$this->expectException(new Exception('Cannot use non-block element as block wrapper'));
$this->obj = new HTMLPurifier_ChildDef_StrictBlockquote('div | p');
$this->config->set('HTML.BlockWrapper', 'dav');
$this->config->set('Cache.DefinitionImpl', null);
Expand Down
4 changes: 2 additions & 2 deletions tests/HTMLPurifier/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testAliases()

$this->assertIdentical($config->get('Home.Rug'), 3);

$this->expectError('Cannot get value from aliased directive, use real name Home.Rug');
$this->expectException(new Exception('Cannot get value from aliased directive, use real name Home.Rug'));
$config->get('Home.Carpet');

$this->expectError('Home.Carpet is an alias, preferred directive name is Home.Rug');
Expand Down Expand Up @@ -384,7 +384,7 @@ public function test_finalize()

$config->finalize();

$this->expectError('Cannot set directive after finalization');
$this->expectException(new Exception('Cannot set directive after finalization'));
$config->set('Poem.Meter', 'vedic');

$this->expectError('Cannot load directives after finalization');
Expand Down
6 changes: 3 additions & 3 deletions tests/HTMLPurifier/ContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public function testStandardUsage()
$this->context->destroy('IDAccumulator');
$this->assertFalse($this->context->exists('IDAccumulator'));

$this->expectError('Attempted to retrieve non-existent variable IDAccumulator');
$this->expectException(new Exception('Attempted to retrieve non-existent variable IDAccumulator'));
$accumulator_3 =& $this->context->get('IDAccumulator');
$this->assertNull($accumulator_3);

$this->expectError('Attempted to destroy non-existent variable IDAccumulator');
$this->expectException(new Exception('Attempted to destroy non-existent variable IDAccumulator'));
$this->context->destroy('IDAccumulator');

}
Expand All @@ -41,7 +41,7 @@ public function testReRegister()
$var = true;
$this->context->register('OnceOnly', $var);

$this->expectError('Name OnceOnly produces collision, cannot re-register');
$this->expectException(new Exception('Name OnceOnly produces collision, cannot re-register'));
$this->context->register('OnceOnly', $var);

// destroy it, now registration is okay
Expand Down
2 changes: 1 addition & 1 deletion tests/HTMLPurifier/DoctypeRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test_get()

$registry = new HTMLPurifier_DoctypeRegistry();

$this->expectError('Doctype XHTML 2.0 does not exist');
$this->expectException(new Exception('Doctype XHTML 2.0 does not exist'));
$registry->get('XHTML 2.0');

// prevent XSS
Expand Down
2 changes: 1 addition & 1 deletion tests/HTMLPurifier/EncoderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function test_convertToUTF8_spuriousEncoding()
{
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
$this->config->set('Core.Encoding', 'utf99');
$this->expectError('Invalid encoding utf99');
$this->expectException(new Exception('Invalid encoding utf99'));
$this->assertIdentical(
HTMLPurifier_Encoder::convertToUTF8("\xF6", $this->config, $this->context),
''
Expand Down
2 changes: 1 addition & 1 deletion tests/HTMLPurifier/HTMLModule/TidyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public function test_makeFixesForLevel_undefinedLevel()
$module = new HTMLPurifier_HTMLModule_Tidy();
$module->defaultLevel = 'bananas';

$this->expectError('Default level bananas does not exist');
$this->expectException(new Exception('Default level bananas does not exist'));

$module->makeFixesForLevel(array(
'fix-1' => 0
Expand Down
2 changes: 1 addition & 1 deletion tests/HTMLPurifier/Strategy/FixNestingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function testInvalidParentError()
// test fallback to div
$this->config->set('HTML.Parent', 'obviously-impossible');
$this->config->set('Cache.DefinitionImpl', null);
$this->expectError('Cannot use unrecognized element as parent');
$this->expectException(new Exception('Cannot use unrecognized element as parent'));
$this->assertResult('<div>Accept</div>');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function test_autoload($class)
}

// after external libraries are loaded, turn on compile time errors
error_reporting(E_ALL | E_STRICT);
error_reporting(E_ALL);

// initialize extra HTML Purifier libraries
require '../extras/HTMLPurifierExtras.auto.php';
Expand Down
5 changes: 2 additions & 3 deletions tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
* $test_files) do not have underscores in their names.
*/

// HTML Purifier runs error free on E_STRICT, so if code reports
// errors, we want to know about it.
error_reporting(E_ALL | E_STRICT);
// HTML Purifier runs error free.
error_reporting(E_ALL);

// Because we always want to know about errors, and because SimpleTest
// will notify us about them, logging the errors to stderr is
Expand Down