#35711 [NEW]: ISO-8859 charset not correctly detected when
From: matteo at beccati dot com
Operating system: Debian GNU/Linux
PHP version: 5.1.1
PHP Bug Type: mbstring related
Bug description: ISO-8859 charset not correctly detected when
Description:
------------
I was evaluating the mbstring extension because of its capabilities to
filter and convert input parameter to the correct encoding. During my test
I found out that an ISO-8859-1 string which ends with an an accented
character is wrongly detected as UTF-8, even if it ends with an incomplete
multibyte character (using iconv to convert the string raises such
notice).
Also reproduced with PHP 4.3.11 on FreeBSD 4 and 5.0.2 on Win32.
Reproduce code:
---------------
<?php
error_reporting(E_ALL);
mb_detect_order('ASCII,UTF-8,ISO-8859-1');
// \xE0 is ISO-8859-1 small a grave char
test_bug("Test: \xE0");
test_bug("Test: \xE0a");
function test_bug($s) {
echo "Trying: ";
var_dump($s);
iconv('UTF8', 'UCS2', $s);
echo "Detected encoding: ".mb_detect_encoding($s)."\n";
echo "Converted string:";
var_dump(mb_convert_encoding($s, 'UTF-8',
'ASCII,UTF-8,ISO-8859-1'));
echo "\n";
}
?>
Expected result:
----------------
Trying: string(7) "Test: à"
Notice: iconv(): Detected an incomplete multibyte character in input
string in test.php on line 13
Detected encoding: ISO-8859-1
Converted string:string(8) "Test: Ã "
Trying: string(8) "Test: àa"
Notice: iconv(): Detected an illegal character in input string in
/var/www/mbstring/test.php on line 13
Detected encoding: ISO-8859-1
Converted string:string(9) "Test: Ã a"
Actual result:
--------------
Trying: string(7) "Test: à"
Notice: iconv(): Detected an incomplete multibyte character in input
string in test.php on line 13
Detected encoding: UTF-8
Converted string:string(6) "Test: "
Trying: string(8) "Test: àa"
Notice: iconv(): Detected an illegal character in input string in
/var/www/mbstring/test.php on line 13
Detected encoding: ISO-8859-1
Converted string:string(9) "Test: Ã a"
--
Edit bug report at http://bugs.php.net/?id=35711&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35711&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35711&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35711&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=35711&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35711&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35711&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35711&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35711&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35711&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35711&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35711&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35711&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35711&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35711&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35711&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35711&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35711&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35711&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35711&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35711&r=mysqlcfg
Thread (18 messages)
- matteo at beccati dot com
- sniper@php.net#35711 [Opn->Asn]: ISO-8859 charset not correctly detected when
- matteo at beccati dot com#35711 [Asn]: ISO-8859 charset not correctly detected when
- matteo at beccati dot com#35711 [Asn]: [PATCH] ISO-8859 charset not correctly detected
- sniper@php.net#35711 [Asn->Fbk]: [PATCH] ISO-8859 charset not correctly detected
- matteo at beccati dot com#35711 [Fbk->Opn]: [PATCH] ISO-8859 charset not correctly detected
- sniper@php.net#35711 [Opn->Asn]: [PATCH] ISO-8859 charset not correctly detected
- hirokawa@php.net#35711 [Asn->Ana]: [PATCH] ISO-8859 charset not correctly detected
- sniper@php.net#35711 [Ana->WFx]: [PATCH] ISO-8859 charset not correctly detected
- matteo at beccati dot com#35711 [WFx]: [PATCH] ISO-8859 charset not correctly detected
- hirokawa@php.net#35711 [WFx->Fbk]: [PATCH] ISO-8859 charset not correctly detected
- hirokawa@php.net#35711 [Fbk->Csd]: [PATCH] ISO-8859 charset not correctly detected
- matteo at beccati dot com#35711 [Csd]: [PATCH] ISO-8859 charset not correctly detected
- matteo at beccati dot com#35711 [Csd->Opn]: [PATCH] ISO-8859 charset not correctly detected
- tony2001@php.net#35711 [Opn->Asn]: [PATCH] ISO-8859 charset not correctly detected
- hirokawa@php.net#35711 [Asn->Ana]: [PATCH] ISO-8859 charset not correctly detected
- sniper@php.net#35711 [Ana->Asn]: [PATCH] ISO-8859 charset not correctly detected
- hirokawa@php.net#35711 [Asn->Csd]: [PATCH] ISO-8859 charset not correctly detected