Bug(?) in serendipity_utf8_encode
Posted: Sat Aug 05, 2006 9:39 am
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):
For yet-unknown reasons, iconv returns FALSE, as defined in http://www.php.net/manual/en/function.iconv.php:
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.
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;
}
}
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.