OSDN Git Service

ツイートのエンティティ情報に重複したインデックスが含まれている場合の対策を追加 (thx @nyamph_pf!)
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 8 Feb 2014 18:35:36 +0000 (03:35 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 8 Feb 2014 18:35:36 +0000 (03:35 +0900)
OpenTween/Resources/ChangeLog.txt
OpenTween/Twitter.cs

index 17fcd98..cf71ff0 100644 (file)
@@ -5,6 +5,7 @@
  * FIX: サムネイル画像の取得をキャンセルするとエラーが発生する場合がある問題の修正
  * FIX: サムネイル画像の読み込み中に画面の更新が遅くなる問題の修正
  * FIX: 壊れたプロフィール画像を取得したり不安定な回線で読み込みを行うと操作不能な状態になることがある問題の修正
+ * FIX: Twitter API から取得したツイートのエンティティ情報が不正な場合の対策を追加 (thx @nyamph_pf!)
 
 ==== Ver 1.1.7(2014/01/16)
  * NEW: ダイレクトメッセージに添付された画像のサムネイル表示に対応
index 2c811ed..b54b8b0 100644 (file)
@@ -2942,20 +2942,26 @@ namespace OpenTween
                 {
                     foreach (var ent in entities.Urls)
                     {
+                        var startIndex = ent.Indices[0];
+                        var endIndex = ent.Indices[1];
+
+                        if (etInfo.ContainsKey(startIndex))
+                            continue;
+
                         if (string.IsNullOrEmpty(ent.DisplayUrl))
                         {
-                            etInfo.Add(ent.Indices[0],
-                                       new EntityInfo {StartIndex = ent.Indices[0],
-                                                       EndIndex = ent.Indices[1],
+                            etInfo.Add(startIndex,
+                                       new EntityInfo {StartIndex = startIndex,
+                                                       EndIndex = endIndex,
                                                        Text = ent.Url,
                                                        Html = "<a href=\"" + ent.Url + "\">" + ent.Url + "</a>"});
                         }
                         else
                         {
                             var expanded = ShortUrl.ResolveMedia(ent.ExpandedUrl, false);
-                            etInfo.Add(ent.Indices[0],
-                                       new EntityInfo {StartIndex = ent.Indices[0],
-                                                       EndIndex = ent.Indices[1],
+                            etInfo.Add(startIndex,
+                                       new EntityInfo {StartIndex = startIndex,
+                                                       EndIndex = endIndex,
                                                        Text = ent.Url,
                                                        Html = "<a href=\"" + ent.Url + "\" title=\"" + MyCommon.ConvertToReadableUrl(expanded) + "\">" + ent.DisplayUrl + "</a>",
                                                        Display = ent.DisplayUrl});
@@ -2967,10 +2973,16 @@ namespace OpenTween
                 {
                     foreach (var ent in entities.Hashtags)
                     {
-                        var hash = Text.Substring(ent.Indices[0], ent.Indices[1] - ent.Indices[0]);
-                        etInfo.Add(ent.Indices[0],
-                                   new EntityInfo {StartIndex = ent.Indices[0],
-                                                   EndIndex = ent.Indices[1],
+                        var startIndex = ent.Indices[0];
+                        var endIndex = ent.Indices[1];
+
+                        if (etInfo.ContainsKey(startIndex))
+                            continue;
+
+                        var hash = Text.Substring(startIndex, endIndex - startIndex);
+                        etInfo.Add(startIndex,
+                                   new EntityInfo {StartIndex = startIndex,
+                                                   EndIndex = endIndex,
                                                    Text = hash,
                                                    Html = "<a href=\"https://twitter.com/search?q=%23" + ent.Text + "\">" + hash + "</a>"});
                         lock (LockObj)
@@ -2983,10 +2995,16 @@ namespace OpenTween
                 {
                     foreach (var ent in entities.UserMentions)
                     {
-                        var screenName = Text.Substring(ent.Indices[0] + 1, ent.Indices[1] - ent.Indices[0] - 1);
-                        etInfo.Add(ent.Indices[0] + 1,
-                                   new EntityInfo {StartIndex = ent.Indices[0] + 1,
-                                                   EndIndex = ent.Indices[1],
+                        var startIndex = ent.Indices[0] + 1;
+                        var endIndex = ent.Indices[1];
+
+                        if (etInfo.ContainsKey(startIndex))
+                            continue;
+
+                        var screenName = Text.Substring(startIndex, endIndex - startIndex);
+                        etInfo.Add(startIndex,
+                                   new EntityInfo {StartIndex = startIndex,
+                                                   EndIndex = endIndex,
                                                    Text = ent.ScreenName,
                                                    Html = "<a href=\"/" + ent.ScreenName + "\">" + screenName + "</a>"});
                         if (!AtList.Contains(ent.ScreenName.ToLower())) AtList.Add(ent.ScreenName.ToLower());
@@ -2998,13 +3016,16 @@ namespace OpenTween
                     {
                         if (ent.Type == "photo")
                         {
+                            var startIndex = ent.Indices[0];
+                            var endIndex = ent.Indices[1];
+
                             // entities.Urls との重複を考慮
-                            if (etInfo.ContainsKey(ent.Indices[0]))
+                            if (etInfo.ContainsKey(startIndex))
                                 continue;
 
-                            etInfo.Add(ent.Indices[0],
-                                       new EntityInfo {StartIndex = ent.Indices[0],
-                                                       EndIndex = ent.Indices[1],
+                            etInfo.Add(startIndex,
+                                       new EntityInfo {StartIndex = startIndex,
+                                                       EndIndex = endIndex,
                                                        Text = ent.Url,
                                                        Html = "<a href=\"" + ent.Url + "\" title=\"" + ent.ExpandedUrl + "\">" + ent.DisplayUrl + "</a>",
                                                        Display = ent.DisplayUrl});