@@ -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