[banshee/stable-2.6] Migo: Fixed parsing RSSs with BOM (bgo#727432)



commit de4d32035e735f694f0537d4fd221e21e607b6a1
Author: Marcin Kolny <marcin kolny gmail com>
Date:   Sun Apr 13 04:27:56 2014 +0200

    Migo: Fixed parsing RSSs with BOM (bgo#727432)
    
    XmlDocument class cannot load an XML string starting with
    the ByteOrderMark characters, so we should remove it before
    serving it to consumers of AsyncWebClient class.
    
    Signed-off-by: Andrés G. Aragoneses <knocte gmail com>

 src/Libraries/Migo/Migo.Net/AsyncWebClient.cs |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
---
diff --git a/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs b/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs
index 18ac5ff..6b05093 100644
--- a/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs
+++ b/src/Libraries/Migo/Migo.Net/AsyncWebClient.cs
@@ -735,12 +735,19 @@ namespace Migo.Net
                                 Match match = encoding_regexp.Match (s);
                                 if (match.Success && match.Groups.Count > 0) {
                                     string encodingStr = match.Groups[1].Value;
+
+                                    Encoding enc = Encoding;
                                     try {
-                                        Encoding enc = Encoding.GetEncoding (encodingStr);
+                                        enc = Encoding.GetEncoding (encodingStr);
                                         if (!enc.Equals (Encoding)) {
                                             s = enc.GetString (resultPtr);
                                         }
                                     } catch (ArgumentException) {}
+
+                                    string bom = enc.GetString (enc.GetPreamble ());
+                                    if (s.StartsWith (bom)) {
+                                        s = s.Remove (0, bom.Length);
+                                    }
                                 }
                             }
                         } catch (Exception ex) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]