OSDN Git Service

リダイレクトの前に空行がある場合にリダイレクトと認識できていなかったのを修正
authorhoneplus <honeplus@users.osdn.me>
Tue, 6 Mar 2012 10:27:52 +0000 (10:27 +0000)
committerhoneplus <honeplus@users.osdn.me>
Tue, 6 Mar 2012 10:27:52 +0000 (10:27 +0000)
git-svn-id: http://svn.osdn.net/svnroot/wptscs/trunk@30 7cc79d57-4d93-40a1-83d5-ec7b38613dec

Wptscs/Parsers/MediaWikiRedirectParser.cs
WptscsTest/Parsers/MediaWikiRedirectParserTest.cs

index f4476aa..e4b995a 100644 (file)
@@ -66,7 +66,8 @@ namespace Honememo.Wptscs.Parsers
 
             // 日本語版みたいに、#REDIRECTと言語固有の#転送みたいなのがあると思われるので、
             // 翻訳元言語とデフォルトの設定でチェック
-            string lower = s.ToLower();
+            string trim = s.TrimStart();
+            string lower = trim.ToLower();
             for (int i = 0; i < 2; i++)
             {
                 string format = this.Website.Redirect;
@@ -78,7 +79,8 @@ namespace Honememo.Wptscs.Parsers
                 if (!String.IsNullOrEmpty(format)
                     && lower.StartsWith(format.ToLower()))
                 {
-                    if (this.LinkParser.TryParse(s.Substring(format.Length).TrimStart(), out result))
+                    // "#REDIRECT "の部分をカットして後ろの[[~]]の部分のリンクを解析
+                    if (this.LinkParser.TryParse(trim.Substring(format.Length).TrimStart(), out result))
                     {
                         return true;
                     }
index 0646db6..6b6541b 100644 (file)
@@ -48,6 +48,13 @@ namespace Honememo.Wptscs.Parsers
                 Assert.AreEqual("Test", link.Title);
                 Assert.AreEqual("Section", link.Section);
 
+                // リダイレクトの前にスペースや空行があってもOK
+                Assert.IsTrue(parser.TryParseToEndCondition(" \r\n \r\n#REDIRECT [[ Test2 ]] \r\n \r\n", null, out element));
+                Assert.IsInstanceOf(typeof(MediaWikiLink), element);
+                link = (MediaWikiLink)element;
+                Assert.AreEqual("Test2", link.Title);
+                Assert.IsNull(link.Section);
+
                 // 普通の記事
                 Assert.IsFalse(parser.TryParseToEndCondition("'''Example''' may refer to:", null, out element));
                 Assert.IsNull(element);