Page 1 of 1

Bug(?) in serendipity_utf8_encode

Posted: Sat Aug 05, 2006 9:39 am
by MatthiasLeisi
A blog that runs in non-UTF-8 mode had empty <title>, <content> etc tags in all feeds (RSS 1.0/2.0, Atom 0.3/1.0 etc). All other elements (eg Links, Dates) were present. A newly created UTF-8 blog showed all content correctly. While hunting down the problem, I noticed that the following code was behaving unexpectedly (include/functions.inc.php, line 480ff):

Code: Select all

function serendipity_utf8_encode($string) {
    if (strtolower(LANG_CHARSET) != 'utf-8') {
        if (function_exists('iconv')) {
            return iconv(LANG_CHARSET, 'UTF-8', $string);
        } else if (function_exists('mb_convert_encoding')) {
            return mb_convert_encoding($string, 'UTF-8', LANG_CHARSET);
        } else {
            return utf8_encode($string);
        }
    } else {
        return $string;
    }
}
For yet-unknown reasons, iconv returns FALSE, as defined in http://www.php.net/manual/en/function.iconv.php:
string iconv ( string in_charset, string out_charset, string str )

Performs a character set conversion on the string str[/] from in_charset to out_charset. Returns the converted string or FALSE on failure.


In order to be safe, serendipity_utf8_encode should check the return value of iconv an fall through on the mb_convert_encoding and/or utf8_encode functions if iconv returns FALSE.

Re: Bug(?) in serendipity_utf8_encode

Posted: Sat Aug 05, 2006 10:59 pm
by garvinhicking
Hi!

Thanks a lot! I stumbled accross that iconv bug in the past, it seems to be caused by some faulty PHP version.

Your suggestion of using a fallback is quite well, I just committed your fix!

Best regards,
Garvin