OSDN Git Service

Twemojiで余分な U+FE0F を絵文字として表示せずに無視する
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 29 Jun 2019 10:56:00 +0000 (19:56 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 29 Jun 2019 16:57:07 +0000 (01:57 +0900)
Fixes: 16184461 ("Twemoji v11.2.0 に対応")

OpenTween.Tests/TweetExtractorTest.cs
OpenTween.Tests/TweetFormatterTest.cs
OpenTween/Resources/ChangeLog.txt
OpenTween/TweetExtractor.cs
OpenTween/TweetFormatter.cs

index c8d3f61..be93e4a 100644 (file)
@@ -228,6 +228,24 @@ namespace OpenTween
         }
 
         [Fact]
+        public void ExtractEmojiEntities_VariationSelector_UnnecessaryEmojiStyleTest()
+        {
+            // 余分な U+FE0F が付いている場合
+            var origText = "🍣\uFE0F"; // U+1F363 + U+FE0F (emoji style)
+            var entities = TweetExtractor.ExtractEmojiEntities(origText).ToArray();
+
+            Assert.Equal(2, entities.Length);
+
+            Assert.Equal(new[] { 0, 1 }, entities[0].Indices);
+            Assert.Equal("🍣", entities[0].Text);
+            Assert.Equal("https://twemoji.maxcdn.com/2/72x72/1f363.png", entities[0].Url);
+
+            Assert.Equal(new[] { 1, 2 }, entities[1].Indices);
+            Assert.Equal("", entities[1].Text);
+            Assert.Equal("", entities[1].Url);
+        }
+
+        [Fact]
         public void ExtractEmojiEntities_CombiningCharacterTest()
         {
             var origText = "#⃣"; // U+0023 U+20E3 (合字)
index 2b9d3a3..967e92c 100644 (file)
@@ -165,7 +165,6 @@ namespace OpenTween
             Assert.Equal(expected, TweetFormatter.AutoLinkHtml(text, entities));
         }
 
-
         [Fact]
         public void FormatEmojiEntity_Test()
         {
@@ -183,6 +182,26 @@ namespace OpenTween
             var expected = "<img class=\"emoji\" src=\"https://twemoji.maxcdn.com/2/72x72/1f363.png\" alt=\"🍣\" />";
             Assert.Equal(expected, TweetFormatter.AutoLinkHtml(text, entities));
         }
+
+        [Fact]
+        public void FormatEmojiEntity_EmptyUrlTest()
+        {
+            // 余分な U+FE0F があった場合に Url が空の絵文字エンティティが渡される
+            var text = "\uFE0F";
+            var entities = new[]
+            {
+                new TwitterEntityEmoji
+                {
+                    Indices = new[] { 0, 1 },
+                    Text = "",
+                    Url = "",
+                },
+            };
+
+            var expected = "";
+            Assert.Equal(expected, TweetFormatter.AutoLinkHtml(text, entities));
+        }
+
         [Fact]
         public void AutoLinkHtml_EntityNullTest()
         {
index 831422d..b385dab 100644 (file)
@@ -2,6 +2,7 @@
 
 ==== Ver 2.3.2-dev(2019/xx/xx)
  * CHG: htn.to の短縮URLを展開する際に強制的にHTTPSを使用する
+ * FIX: Twemojiを有効にすると絵文字の後に余分な文字が表示される場合がある不具合を修正
 
 ==== Ver 2.3.1(2019/04/22)
  * FIX: 2019/5/20に予定されているTwitter APIの仕様変更によりエラーが発生する問題を修正
index 18504a0..653afda 100644 (file)
@@ -182,12 +182,27 @@ namespace OpenTween
                 var startPos = text.GetCodepointCount(0, match.Index);
                 var endPos = startPos + text.GetCodepointCount(match.Index, match.Index + match.Length);
 
-                yield return new TwitterEntityEmoji
+                TwitterEntityEmoji entity;
+                if (codepointHex.Count >= 1)
                 {
-                    Indices = new[] { startPos, endPos },
-                    Text = input,
-                    Url = "https://twemoji.maxcdn.com/2/72x72/" + string.Join("-", codepointHex) + ".png",
-                };
+                    entity = new TwitterEntityEmoji
+                    {
+                        Indices = new[] { startPos, endPos },
+                        Text = input,
+                        Url = "https://twemoji.maxcdn.com/2/72x72/" + string.Join("-", codepointHex) + ".png",
+                    };
+                }
+                else
+                {
+                    entity = new TwitterEntityEmoji
+                    {
+                        Indices = new[] { startPos, endPos },
+                        Text = input,
+                        Url = "",
+                    };
+                }
+
+                yield return entity;
             }
         }
     }
index 733141d..9969c3a 100644 (file)
@@ -166,6 +166,9 @@ namespace OpenTween
             if (!SettingManager.Local.UseTwemoji)
                 return t(e(targetText));
 
+            if (string.IsNullOrEmpty(entity.Url))
+                return "";
+
             return "<img class=\"emoji\" src=\"" + e(entity.Url) + "\" alt=\"" + e(entity.Text) + "\" />";
         }