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