OSDN Git Service

関連発言表示に含めるパーマリンクURLの正規表現を修正
authorKimura Youichi <kim.upsilon@bucyou.net>
Tue, 9 Apr 2013 17:00:22 +0000 (02:00 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sun, 14 Apr 2013 12:40:26 +0000 (21:40 +0900)
OpenTween.Tests/OpenTween.Tests.csproj
OpenTween.Tests/TwitterTest.cs [new file with mode: 0644]
OpenTween/Resources/ChangeLog.txt
OpenTween/Twitter.cs

index e5df0a2..cf4dfa2 100644 (file)
@@ -67,6 +67,7 @@
     <Compile Include="Thumbnail\Services\TinamiTest.cs" />
     <Compile Include="ToolStripAPIGaugeTest.cs" />
     <Compile Include="TweetThumbnailTest.cs" />
+    <Compile Include="TwitterTest.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\OpenTween\OpenTween.csproj">
diff --git a/OpenTween.Tests/TwitterTest.cs b/OpenTween.Tests/TwitterTest.cs
new file mode 100644 (file)
index 0000000..a775b82
--- /dev/null
@@ -0,0 +1,51 @@
+// OpenTween - Client of Twitter
+// Copyright (c) 2013 kim_upsilon (@kim_upsilon) <https://upsilo.net/~upsilon/>
+// All rights reserved.
+//
+// This file is part of OpenTween.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program. If not, see <http://www.gnu.org/licenses/>, or write to
+// the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
+// Boston, MA 02110-1301, USA.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using NUnit.Framework;
+
+namespace OpenTween
+{
+    [TestFixture]
+    class TwitterTest
+    {
+        [TestCase("https://twitter.com/twitterapi/status/22634515958",
+            Result = new[] { "22634515958" })]
+        [TestCase("<a target=\"_self\" href=\"https://t.co/aaaaaaaa\" title=\"https://twitter.com/twitterapi/status/22634515958\">twitter.com/twitterapi/stat…</a>",
+            Result = new[] { "22634515958" })]
+        [TestCase("<a target=\"_self\" href=\"https://t.co/bU3oR95KIy\" title=\"https://twitter.com/haru067/status/224782458816692224\">https://t.co/bU3oR95KIy</a>" +
+            "<a target=\"_self\" href=\"https://t.co/bbbbbbbb\" title=\"https://twitter.com/karno/status/311081657790771200\">https://t.co/bbbbbbbb</a>",
+            Result = new[] { "224782458816692224", "311081657790771200" })]
+        [TestCase("https://mobile.twitter.com/muji_net/status/21984934471",
+            Result = new[] { "21984934471" })]
+        [TestCase("https://twitter.com/imgazyobuzi/status/293333871171354624/photo/1",
+            Result = new[] { "293333871171354624" })]
+        public string[] StatusUrlRegexTest(string url)
+        {
+            return Twitter.StatusUrlRegex.Matches(url).Cast<Match>()
+                .Select(x => x.Groups["StatusId"].Value).ToArray();
+        }
+    }
+}
index 594d8b9..529d9cb 100644 (file)
@@ -2,6 +2,7 @@
 
 ==== Ver 1.1.0-beta1(2013/xx/xx)
  * NEW: タブの表示位置を画面上部に変更可能に (thx @aokomoriuta!)
+ * NEW: mobile.twitter.com/<スクリーン名>/status/<ステータスID> のURLも関連発言表示の対象に追加
  * FIX: スペースが含まれているURLをブラウザで開こうとするとURLが分断されて複数のタブが開いてしまう問題を修正 (thx @5px!)
  * FIX: 画面更新時にInvalidOperationExceptionのエラーが発生する不具合を修正
 
index 5d362dc..b951139 100644 (file)
@@ -117,6 +117,11 @@ namespace OpenTween
         /// </summary>
         public const string ServiceAvailabilityStatusUrl = "https://status.io.watchmouse.com/7617";
 
+        /// <summary>
+        /// ツイートへのパーマリンクURLを判定する正規表現
+        /// </summary>
+        public static readonly Regex StatusUrlRegex = new Regex(@"https?://([^.]+\.)?twitter\.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)/status(es)?/(?<StatusId>[0-9]+)(/photo)?", RegexOptions.IgnoreCase);
+
         delegate void GetIconImageDelegate(PostClass post);
         private readonly object LockObj = new object();
         private List<long> followerId = new List<long>();
@@ -2616,9 +2621,8 @@ namespace OpenTween
             //}
             //return rslt;
 
-
             //MRTとかに対応のためツイート内にあるツイートを指すURLを取り込む
-            var ma = Regex.Matches(tab.RelationTargetPost.Text, "title=\"https?://twitter.com/(#!/)?(?<ScreenName>[a-zA-Z0-9_]+)(/status(es)?/(?<StatusId>[0-9]+))\"");
+            var ma = Twitter.StatusUrlRegex.Matches(tab.RelationTargetPost.Text);
             foreach (Match _match in ma)
             {
                 Int64 _statusId;