Bug #52211 [Com]: iconv() returns part of string on error

From: Date: Sun, 29 Oct 2017 19:58:58 +0000
Subject: Bug #52211 [Com]: iconv() returns part of string on error
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-212359@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=52211&edit=1

 ID:                 52211
 Comment by:         hho2002 at gmail dot com
 Reported by:        raphgivernaud at yahoo dot fr
 Summary:            iconv() returns part of string on error
 Status:             Closed
 Type:               Bug
 Package:            ICONV related
 Operating System:   Windows Vista
 PHP Version:        5.3.2
 Assigned To:        felipe
 Block user comment: N
 Private report:     N

 New Comment:

Description:
------------
Fixed bug #52211 (iconv() returns part of string on error)
http://svn.php.net/viewvc/?view=revision&revision=300894
http://git.php.net/?p=php-src.git;a=commit;h=e3fdf31b0bf3b7b799ea25ba5ec14be194813e0b

This fix make "iconv() with //IGNORE" return false

Test script:
---------------
<?php
    $str = "\xC3\xE6\xBC\xEC\xCC\xD6\xC9\xEE\xBF";
    $str_iconv = iconv('GBK', 'UTF-8//IGNORE', $str);
    var_dump($str_iconv);
?>

Expected result:
----------------
Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d
string(12) "\xE9\x9D\xA2\xE6\xA3\x80\xE8\xAE\xA8\xE6\xB7\xB1"

Actual result:
--------------
Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d
bool(false)


Previous Comments:
------------------------------------------------------------------------
[2017-10-29 19:58:53] hho2002 at gmail dot com

Description:
------------
Fixed bug #52211 (iconv() returns part of string on error)
http://svn.php.net/viewvc/?view=revision&amp;revision=300894
http://git.php.net/?p=php-src.git;a=commit;h=e3fdf31b0bf3b7b799ea25ba5ec14be194813e0b

This fix make "iconv() with //IGNORE" return false

Test script:
---------------
<?php
    $str = "\xC3\xE6\xBC\xEC\xCC\xD6\xC9\xEE\xBF";
    $str_iconv = iconv('GBK', 'UTF-8//IGNORE', $str);
    var_dump($str_iconv);
?>

Expected result:
----------------
Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d
string(12) "\xE9\x9D\xA2\xE6\xA3\x80\xE8\xAE\xA8\xE6\xB7\xB1"

Actual result:
--------------
Notice: iconv(): Detected an incomplete multibyte character in input string in %s on line %d
bool(false)

------------------------------------------------------------------------
[2015-05-11 21:29:28] cmb@php.net

> I note that the docs still reflect the old behavior...

Which docs? <http://php.net/manual/en/function.iconv.php>
seems to be fine.

------------------------------------------------------------------------
[2015-05-08 19:11:38] stas@php.net

I note that the docs still reflect the old behavior...

------------------------------------------------------------------------
[2012-01-08 12:34:10] pajoye@php.net

This is a totally unrelated issue to what you try to explain. And you already have 
a report for this, #48147

------------------------------------------------------------------------
[2011-12-18 18:36:25] ezyang@php.net

I don't think this bug was fixed correctly. In particular, iconv doesn't handle
'//IGNORE' correctly now.

ezyang@javelin:~$ cat test.php
<?php var_dump(iconv("UTF-8", "ISO-8859-1//IGNORE",
"\xE4\xB8\xAD"));
ezyang@javelin:~$ php --version
PHP 5.3.6-13ubuntu3.3 with Suhosin-Patch (cli) (built: Dec 13 2011 18:37:10) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
    with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
ezyang@javelin:~$ php test.php
PHP Notice:  iconv(): Detected an illegal character in input string in /home/ezyang/test.php on line
1
PHP Stack trace:
PHP   1. {main}() /home/ezyang/test.php:0
PHP   2. iconv() /home/ezyang/test.php:1
string(0) ""
ezyang@javelin:~$ phpv 5.4.0RC3 --version
PHP 5.4.0RC3 (cli) (built: Dec 16 2011 15:14:12) 
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2011 Zend Technologies
ezyang@javelin:~$ phpv 5.4.0RC3 test.php
bool(false)

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=52211


--
Edit this bug report at https://bugs.php.net/bug.php?id=52211&edit=1


Thread (10 messages)

« previous php.bugs (#212359) next »