Merge pull request #4418 from Karlson2k/fix_xml_enc
authorjmarshallnz <jcmarsha@gmail.com>
Fri, 21 Mar 2014 05:36:38 +0000 (18:36 +1300)
committerTrent Nelson <trent.a.b.nelson@gmail.com>
Fri, 21 Mar 2014 22:58:34 +0000 (16:58 -0600)
[scrapers] Fix processing xml files with incorrect suggested encoding or incorrect encoding in xml declaration

xbmc/addons/Scraper.cpp
xbmc/utils/ScraperUrl.cpp
xbmc/utils/XBMCTinyXML.cpp

index 22290d9..894338e 100644 (file)
@@ -256,7 +256,8 @@ vector<CStdString> CScraper::Run(const CStdString& function,
   CLog::Log(LOGDEBUG,"scraper: %s returned %s",function.c_str(),strXML.c_str());
 
   CXBMCTinyXML doc;
-  doc.Parse(strXML, TIXML_ENCODING_UNKNOWN);
+  /* all data was converted to UTF-8 before being processed by scraper */
+  doc.Parse(strXML, TIXML_ENCODING_UTF8);
   if (!doc.RootElement())
   {
     CLog::Log(LOGERROR, "%s: Unable to parse XML",__FUNCTION__);
index ba79d13..907d0f4 100644 (file)
@@ -126,7 +126,9 @@ bool CScraperUrl::ParseString(CStdString strUrl)
     return false;
 
   CXBMCTinyXML doc;
-  doc.Parse(strUrl, TIXML_ENCODING_UNKNOWN);
+  /* strUrl is coming from internal sources (usually generated by scraper or from database)
+   * so strUrl is always in UTF-8 */
+  doc.Parse(strUrl, TIXML_ENCODING_UTF8);
 
   TiXmlElement* pElement = doc.RootElement();
   if (!pElement)
@@ -326,7 +328,8 @@ bool CScraperUrl::ParseEpisodeGuide(CStdString strUrls)
 
   // ok, now parse the xml file
   CXBMCTinyXML doc;
-  doc.Parse(strUrls, TIXML_ENCODING_UNKNOWN);
+  /* strUrls is coming from internal sources so strUrls is always in UTF-8 */
+  doc.Parse(strUrls, TIXML_ENCODING_UTF8);
   if (doc.RootElement())
   {
     TiXmlHandle docHandle( &doc );
index e29f8e5..f29049f 100644 (file)
@@ -179,7 +179,9 @@ bool CXBMCTinyXML::TryParse(const std::string& data, const std::string& tryDataC
   else if (!tryDataCharset.empty())
   {
     std::string converted;
-    if (!g_charsetConverter.ToUtf8(tryDataCharset, data, converted) || converted.empty())
+    /* some wrong conversions can leave US-ASCII XML header and structure untouched but break non-English data
+     * so conversion must fail on wrong character and then other encodings will be tried */
+    if (!g_charsetConverter.ToUtf8(tryDataCharset, data, converted, true) || converted.empty())
       return false; // can't convert data
 
     InternalParse(converted, TIXML_ENCODING_UTF8);