0
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2024-11-09 15:28:40 +00:00

Do checks against iconvAvailable because PHP 5.4 has botched iconv support.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
This commit is contained in:
Edward Z. Yang 2012-10-27 02:27:57 -07:00
parent 83a574491e
commit c0ad68108a
4 changed files with 17 additions and 9 deletions

View File

@ -355,7 +355,12 @@ class HTMLPurifier_Encoder
$str = utf8_encode($str);
return $str;
}
trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
$bug = HTMLPurifier_Encoder::testIconvTruncateBug();
if ($bug == self::ICONV_OK) {
trigger_error('Encoding not supported, please install iconv', E_USER_ERROR);
} else {
trigger_error('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);
}
}
/**

View File

@ -39,6 +39,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
}
function test_convertToUTF8_spuriousEncoding() {
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
$this->config->set('Core.Encoding', 'utf99');
$this->expectError('Invalid encoding utf99');
$this->assertIdentical(
@ -87,7 +88,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
}
function test_convertFromUTF8_iconvNoChars() {
if (!function_exists('iconv')) return;
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->assertIdentical(
HTMLPurifier_Encoder::convertFromUTF8($this->getZhongWen(), $this->config, $this->context),
@ -169,14 +170,16 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
}
function test_testEncodingSupportsASCII() {
$this->assertASCIISupportCheck('Shift_JIS', array("\xC2\xA5" => '\\', "\xE2\x80\xBE" => '~'));
$this->assertASCIISupportCheck('JOHAB', array("\xE2\x82\xA9" => '\\'));
if (HTMLPurifier_Encoder::iconvAvailable()) {
$this->assertASCIISupportCheck('Shift_JIS', array("\xC2\xA5" => '\\', "\xE2\x80\xBE" => '~'));
$this->assertASCIISupportCheck('JOHAB', array("\xE2\x82\xA9" => '\\'));
}
$this->assertASCIISupportCheck('ISO-8859-1', array());
$this->assertASCIISupportCheck('dontexist', array()); // canary
}
function testShiftJIS() {
if (!function_exists('iconv')) return;
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
$this->config->set('Core.Encoding', 'Shift_JIS');
// This actually looks like a Yen, but we're going to treat it differently
$this->assertIdentical(
@ -190,7 +193,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
}
function testIconvTruncateBug() {
if (!function_exists('iconv')) return;
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
if (HTMLPurifier_Encoder::testIconvTruncateBug() !== HTMLPurifier_Encoder::ICONV_TRUNCATES) return;
$this->config->set('Core.Encoding', 'ISO-8859-1');
$this->assertIdentical(
@ -200,7 +203,7 @@ class HTMLPurifier_EncoderTest extends HTMLPurifier_Harness
}
function testIconvChunking() {
if (!function_exists('iconv')) return;
if (!HTMLPurifier_Encoder::iconvAvailable()) return;
if (HTMLPurifier_Encoder::testIconvTruncateBug() !== HTMLPurifier_Encoder::ICONV_TRUNCATES) return;
$this->assertIdentical(HTMLPurifier_Encoder::iconv('utf-8', 'iso-8859-1//IGNORE', "a\xF3\xA0\x80\xA0b", 4), 'ab');
$this->assertIdentical(HTMLPurifier_Encoder::iconv('utf-8', 'iso-8859-1//IGNORE', "aa\xE4\xB8\xADb", 4), 'aab');

View File

@ -1,5 +1,5 @@
--SKIPIF--
if (!function_exists('iconv')) return true;
if (!HTMLPurifier_Encoder::iconvAvailable()) return true;
--INI--
Core.Encoding = "Shift_JIS"
Core.EscapeNonASCIICharacters = true

View File

@ -1,5 +1,5 @@
--SKIPIF--
if (!function_exists('iconv')) return true;
if (!HTMLPurifier_Encoder::iconvAvailable()) return true;
--INI--
Core.Encoding = Shift_JIS
--HTML--