From: Andrew Dolgov Date: Mon, 5 Sep 2016 12:02:31 +0000 (+0300) Subject: parser: only try to convert encoding if mbstring actually supports it X-Git-Tag: 17.1~40 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=cde827220532a3e8f32fb30ac670deb0e91f9dad;p=tt-rss.git parser: only try to convert encoding if mbstring actually supports it --- diff --git a/classes/feedparser.php b/classes/feedparser.php index 9247bf45..3296381e 100644 --- a/classes/feedparser.php +++ b/classes/feedparser.php @@ -15,7 +15,11 @@ class FeedParser { function normalize_encoding($data) { if (preg_match('/^(<\?xml[\t\n\r ].*?encoding[\t\n\r ]*=[\t\n\r ]*["\'])(.+?)(["\'].*?\?>)/s', $data, $matches) === 1) { - $data = mb_convert_encoding($data, 'UTF-8', $matches[2]); + + $encoding = strtolower($matches[2]); + + if (in_array($encoding, mb_list_encodings())) + $data = mb_convert_encoding($data, 'UTF-8', $encoding); $data = preg_replace('/^<\?xml[\t\n\r ].*?\?>/s', $matches[1] . "UTF-8" . $matches[3] , $data); }