1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-07-31 11:20:13 +02:00

[2.1.4] [MFH] Encoder optimization and shut-up operator bugfix from r1680

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/branches/php4@1718 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2008-05-15 05:16:36 +00:00
parent 9f23bc005b
commit 5fa575f8ac
2 changed files with 17 additions and 1 deletions

2
NEWS
View File

@@ -17,6 +17,7 @@ ERRATA
2.1.4, unknown release date
! DefinitionCacheFactory now can register new implementations
! CSS properties are now case-insensitive
! Encoder optimized with valid UTF-8 input
- Colors missing # but in hex form will be corrected
- CSS Number algorithm improved
- Autoclose now operates iteratively, i.e. <span><span><div> now has
@@ -26,6 +27,7 @@ ERRATA
- Fix bug with rgb(0, 1, 2) color syntax with spaces inside shorthand syntax
- HTMLPurifier_HTMLDefinition->addAttribute can now be called multiple times
on the same element without emitting errors.
- Iconv uses set_error_handler instead of shut-up operator
2.1.3, released 2007-11-05
! tests/multitest.php allows you to test multiple versions by running

View File

@@ -62,6 +62,11 @@ class HTMLPurifier_Encoder
trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
}
/**
* Error-handler that mutes errors, alternative to shut-up operator.
*/
function muteErrorHandler() {}
/**
* Cleans a UTF-8 string for well-formedness and SGML validity
*
@@ -106,9 +111,18 @@ class HTMLPurifier_Encoder
static $iconv = null;
if ($iconv === null) $iconv = function_exists('iconv');
// UTF-8 validity is checked since PHP 4.3.5
// This is an optimization: if the string is already valid UTF-8, no
// need to do iconv/php stuff. 99% of the time, this will be the case.
if (preg_match('/^.{1}/us', $str)) {
return strtr($str, $non_sgml_chars);
}
if ($iconv && !$force_php) {
// do the shortcut way
$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
set_error_handler(array('HTMLPurifier_Encoder', 'muteErrorHandler'));
$str = iconv('UTF-8', 'UTF-8//IGNORE', $str);
restore_error_handler();
return strtr($str, $non_sgml_chars);
}