Blob Blame History Raw
diff -up banshee-2.6.2/src/Libraries/Migo/Migo.Syndication/RssParser.cs.dos2unix banshee-2.6.2/src/Libraries/Migo/Migo.Syndication/RssParser.cs
--- banshee-2.6.2/src/Libraries/Migo/Migo.Syndication/RssParser.cs.dos2unix	2014-02-18 15:35:24.000000000 -0500
+++ banshee-2.6.2/src/Libraries/Migo/Migo.Syndication/RssParser.cs	2017-08-31 10:45:49.868223559 -0400
@@ -54,26 +54,49 @@ namespace Migo.Syndication
             try {
                 doc.LoadXml (xml);
             } catch (XmlException e) {
-                bool have_stripped_control = false;
-                StringBuilder sb = new StringBuilder ();
-
-                foreach (char c in xml) {
-                    if (Char.IsControl (c) && c != '\n') {
-                        have_stripped_control = true;
-                    } else {
-                        sb.Append (c);
-                    }
-                }
-
                 bool loaded = false;
-                if (have_stripped_control) {
+                string DosLineBreak = "\r\n";
+                var encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true);
+                string _byteOrderMarkUtf8 = encoding.GetString(encoding.GetPreamble());
+                if (System.Text.RegularExpressions.Regex.IsMatch(xml, DosLineBreak, System.Text.RegularExpressions.RegexOptions.IgnoreCase)) {
+                    Hyena.Log.Warning ("DosLineBreaks detected in xml");
+                    string result = xml.Replace("\r", "");
+                    if (result.StartsWith(_byteOrderMarkUtf8, StringComparison.Ordinal)) {
+                        Hyena.Log.Warning ("UTF-8 BOM detected in xml");
+                        result = result.Remove(0, _byteOrderMarkUtf8.Length);
+                    }
+                    if (result.StartsWith("\uFEFF", StringComparison.Ordinal)) {
+                        Hyena.Log.Warning ("UTF-16 BOM detected in xml");
+                        result.Trim(new char[]{'\uFEFF','\u200B'});
+                    }
                     try {
-                        doc.LoadXml (sb.ToString ());
+                        doc.LoadXml (result);
                         loaded = true;
                     } catch (Exception) {
                     }
                 }
 
+                if (!loaded) {
+                    bool have_stripped_control = false;
+                    StringBuilder sb = new StringBuilder ();
+
+                    foreach (char c in xml) {
+                        if (Char.IsControl (c) && c != '\n') {
+                            have_stripped_control = true;
+                        } else {
+                            sb.Append (c);
+                        }
+                    }
+
+                    if (have_stripped_control) {
+                        try {
+                            doc.LoadXml (sb.ToString ());
+                            loaded = true;
+                        } catch (Exception) {
+                        }
+                    }
+                }
+
                 if (!loaded) {
                     Hyena.Log.Exception (e);
                     throw new FormatException ("Invalid XML document.");