mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 15:28:40 +00:00
[3.1.0] Encoder optimization, as suggested by Diego
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1680 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
e9c7873057
commit
c4aa3ee40c
2
NEWS
2
NEWS
@ -12,7 +12,9 @@ NEWS ( CHANGELOG and HISTORY ) HTMLPurifier
|
|||||||
3.1.0, unknown release date
|
3.1.0, unknown release date
|
||||||
- InterchangeBuilder now alphabetizes its lists
|
- InterchangeBuilder now alphabetizes its lists
|
||||||
- Validation error in configdoc output fixed
|
- Validation error in configdoc output fixed
|
||||||
|
- Iconv errors muted even with custom error handlers
|
||||||
. Out-of-date documentation revised
|
. Out-of-date documentation revised
|
||||||
|
. UTF-8 encoding check optimization as suggested by Diego
|
||||||
|
|
||||||
3.1.0rc1, released 2008-04-22
|
3.1.0rc1, released 2008-04-22
|
||||||
# Autoload support added. Internal require_once's removed in favor of an
|
# Autoload support added. Internal require_once's removed in favor of an
|
||||||
|
9
TODO
9
TODO
@ -29,11 +29,14 @@ NICE FEATURES
|
|||||||
|
|
||||||
BUGS
|
BUGS
|
||||||
- Style attribute height/width limiting for images
|
- Style attribute height/width limiting for images
|
||||||
- Easy way to blacklist elements and attributes
|
|
||||||
- Investigate iconv error emitting
|
|
||||||
- Investigate UTF-8 optimization <http://htmlpurifier.org/phorum/read.php?3,1496>
|
|
||||||
- Figure out what to do about target="" and name="", since they show up so often
|
- Figure out what to do about target="" and name="", since they show up so often
|
||||||
|
|
||||||
|
EXTERNAL
|
||||||
|
- Improve Phorum install documentation
|
||||||
|
- Mia
|
||||||
|
- Aliro
|
||||||
|
- Comparison: http://code.iamcal.com/php/lib_filter/
|
||||||
|
|
||||||
FUTURE VERSIONS
|
FUTURE VERSIONS
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
@ -14,6 +14,11 @@ class HTMLPurifier_Encoder
|
|||||||
trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
|
trigger_error('Cannot instantiate encoder, call methods statically', E_USER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error-handler that mutes errors, alternative to shut-up operator.
|
||||||
|
*/
|
||||||
|
private static function muteErrorHandler() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans a UTF-8 string for well-formedness and SGML validity
|
* Cleans a UTF-8 string for well-formedness and SGML validity
|
||||||
*
|
*
|
||||||
@ -57,9 +62,18 @@ class HTMLPurifier_Encoder
|
|||||||
static $iconv = null;
|
static $iconv = null;
|
||||||
if ($iconv === null) $iconv = function_exists('iconv');
|
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) {
|
if ($iconv && !$force_php) {
|
||||||
// do the shortcut way
|
// 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);
|
return strtr($str, $non_sgml_chars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user