OSDN Git Service

不正なフォーマットの起動オプションを判定する条件が適切でない問題を修正 (thx @anikiti07!)
authorKimura Youichi <kim.upsilon@bucyou.net>
Tue, 19 Nov 2013 13:33:33 +0000 (22:33 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Tue, 19 Nov 2013 13:34:20 +0000 (22:34 +0900)
OpenTween.Tests/MyApplicationTest.cs
OpenTween/ApplicationEvents.cs

index 12668a6..0d53568 100644 (file)
@@ -82,5 +82,13 @@ namespace OpenTween
                 {"foo", ""},
             }));
         }
+
+        [Test]
+        public void IgroreInvalidOptionsTest()
+        {
+            var args = new string[] { "--foo", "/" };
+
+            Assert.That(MyApplication.ParseArguments(args), Is.Empty);
+        }
     }
 }
index b8d73da..459466b 100644 (file)
@@ -28,6 +28,7 @@
 using System;
 using System.Collections.Generic;
 using System.IO;
+using System.Linq;
 using System.Diagnostics;
 using System.Windows.Forms;
 using System.Text.RegularExpressions;
@@ -88,19 +89,11 @@ namespace OpenTween
 
         internal static IDictionary<string, string> ParseArguments(IEnumerable<string> arguments)
         {
-            var results = new Dictionary<string, string>();
             var optionPattern = new Regex(@"^/(.+?)(?::(.*))?$");
 
-            foreach (var arg in arguments)
-            {
-                var match = optionPattern.Match(arg);
-                if (match == null)
-                    continue;
-
-                results[match.Groups[1].Value] = match.Groups[2].Value;
-            }
-
-            return results;
+            return arguments.Select(x => optionPattern.Match(x))
+                .Where(x => x.Success)
+                .ToDictionary(x => x.Groups[1].Value, x => x.Groups[2].Value);
         }
 
         private static void ShowPreviousWindow()