[banshee] [Migo] Ignore invalid RSS durations; tests pass



commit 6276e2984cfe8bca291ea711b1054517c20cb41d
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Sun Mar 14 14:42:54 2010 -0700

    [Migo] Ignore invalid RSS durations; tests pass

 src/Libraries/Migo/Migo.Syndication/RssParser.cs   |   22 +++++++++++--------
 .../Migo/Migo.Syndication/Tests/XmlTests.cs        |    1 -
 2 files changed, 13 insertions(+), 10 deletions(-)
---
diff --git a/src/Libraries/Migo/Migo.Syndication/RssParser.cs b/src/Libraries/Migo/Migo.Syndication/RssParser.cs
index 5d77f7a..8bbff2b 100644
--- a/src/Libraries/Migo/Migo.Syndication/RssParser.cs
+++ b/src/Libraries/Migo/Migo.Syndication/RssParser.cs
@@ -279,19 +279,23 @@ namespace Migo.Syndication
                 return TimeSpan.Zero;
             }
 
-            int hours = 0, minutes = 0, seconds = 0;
-            string [] parts = duration.Split (':');
+            try {
+                int hours = 0, minutes = 0, seconds = 0;
+                string [] parts = duration.Split (':');
 
-            if (parts.Length > 0)
-                seconds = Int32.Parse (parts[parts.Length - 1]);
+                if (parts.Length > 0)
+                    seconds = Int32.Parse (parts[parts.Length - 1]);
 
-            if (parts.Length > 1)
-                minutes = Int32.Parse (parts[parts.Length - 2]);
+                if (parts.Length > 1)
+                    minutes = Int32.Parse (parts[parts.Length - 2]);
 
-            if (parts.Length > 2)
-                hours = Int32.Parse (parts[parts.Length - 3]);
+                if (parts.Length > 2)
+                    hours = Int32.Parse (parts[parts.Length - 3]);
 
-            return TimeSpan.FromSeconds (hours * 3600 + minutes * 60 + seconds);
+                return TimeSpan.FromSeconds (hours * 3600 + minutes * 60 + seconds);
+            } catch {
+                return TimeSpan.Zero;
+            }
         }
 
 #region Xml Convienience Methods
diff --git a/src/Libraries/Migo/Migo.Syndication/Tests/XmlTests.cs b/src/Libraries/Migo/Migo.Syndication/Tests/XmlTests.cs
index 95a09b0..3902016 100644
--- a/src/Libraries/Migo/Migo.Syndication/Tests/XmlTests.cs
+++ b/src/Libraries/Migo/Migo.Syndication/Tests/XmlTests.cs
@@ -91,7 +91,6 @@ namespace Migo.Syndication.Tests
         {
             foreach (string file in System.IO.Directory.GetFiles (rss_directory)) {
                 if (file.EndsWith (".rss.gz")) {
-                    Console.WriteLine ("Have rss file: {0}", file);
                     using (var stream = System.IO.File.OpenRead (file)) {
                         using (var gzip_stream = new GZipInputStream (stream)) {
                             using (var txt_stream = new System.IO.StreamReader (gzip_stream)) {



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