From 0a4cf5ca50dc225931682195cd0fd36cd6ec9e62 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 19 Aug 2010 11:07:14 -0600 Subject: [PATCH] Bug #9187: Use same DOM loading technique that we use for XSS filter --- framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php b/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php index 71751feae..9212d9604 100644 --- a/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php +++ b/framework/Text_Filter/lib/Horde/Text/Filter/Html2text.php @@ -102,11 +102,14 @@ class Horde_Text_Filter_Html2text extends Horde_Text_Filter_Base public function postProcess($text) { if (extension_loaded('dom')) { - $text = Horde_String::convertCharset($text, $this->_params['charset'], 'UTF-8'); - $old_error = libxml_use_internal_errors(true); $doc = new DOMDocument(); - $doc->loadHTML('' . $text); + $doc->loadHTML($text); + if (!$doc->encoding) { + /* If libxml can't auto-detect encoding, convert to ISO-8859-1 + * manually. */ + $doc->loadHTML(Horde_String::convertCharset($text, $this->_params['charset'], 'ISO-8859-1')); + } if ($old_error) { libxml_use_internal_errors(false); } -- 2.11.0