Commits

Matt Hamilton committed 54e1386

Protect against invalid entity indices in RT in search result (Twitter API bug)

  • Participants
  • Parent commits 972ff63

Comments (0)

Files changed (2)

Source/Halfwit2/Extensions/TweetableExtensions.cs

 using System;
+using System.Linq;
 using System.Net;
 using System.Windows;
 using System.Windows.Controls;
             var i = 0;
             string text;
             TwitterEntityCollection entities;
-           
+
             // if it's a retweet, use the original text
             if (item.IsRetweet && item.Context != null)
             {
                 TextWrapping = System.Windows.TextWrapping.Wrap,
             };
 
+
             foreach (var e in entities)
             {
+                if (e.Indices.Item1 > text.Length || e.Indices.Item2 > text.Length) continue;
+
                 if (e.Indices.Item1 > i)
                 {
                     textBlock.Inlines.Add(new Run(WebUtility.HtmlDecode(text.Substring(i, e.Indices.Item1 - i))));
         {
             var span = DateTime.Now.Subtract(date);
 
-            if (span.Days > 100) return "A while ago";
-            if (span.Days > 50) return "A few months ago";
-            if (span.Days > 30) return "About a month ago";
+            if (span.Days > 300) return date.ToString("MMM yy");
+            if (span.Days > 1) return date.ToString("dd MMM");
 
-            if (span.Days > 14) return "A few weeks ago";
-            if (span.Days > 7) return "About a week ago";
-
-            if (span.Days > 1) return span.Days + " days ago";
             if (span.Days == 1) return "Yesterday";
 
             if (span.Hours > 1) return span.Hours + " hours ago";

Source/Halfwit2/Halfwit2.csproj

     <PublisherName>Mad Props!</PublisherName>
     <CreateWebPageOnPublish>true</CreateWebPageOnPublish>
     <WebPage>publish.htm</WebPage>
-    <ApplicationRevision>60</ApplicationRevision>
+    <ApplicationRevision>61</ApplicationRevision>
     <ApplicationVersion>2.0.0.%2a</ApplicationVersion>
     <UseApplicationTrust>false</UseApplicationTrust>
     <PublishWizardCompleted>true</PublishWizardCompleted>