OSDN Git Service

小数点にピリオド以外の記号を用いるカルチャで double.Parse に失敗する不具合を修正 (thx @Xiatian!)
authorKimura Youichi <kim.upsilon@bucyou.net>
Sat, 26 Nov 2016 03:32:43 +0000 (12:32 +0900)
committerKimura Youichi <kim.upsilon@bucyou.net>
Sat, 26 Nov 2016 03:35:23 +0000 (12:35 +0900)
https://osdn.net/ticket/browse.php?group_id=6526&tid=35878

Fixes: 74df0fc9 ("動作しなくなっていたFoursquareのサムネイル表示を再実装")

OpenTween.Tests/Thumbnail/Services/FoursquareCheckinTest.cs
OpenTween/Resources/ChangeLog.txt
OpenTween/Thumbnail/Services/FoursquareCheckin.cs

index d10db26..fe97164 100644 (file)
@@ -21,6 +21,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Linq;
 using System.Net;
 using System.Net.Http;
@@ -236,6 +237,39 @@ namespace OpenTween.Thumbnail.Services
         }
 
         [Fact]
+        public void ParseInLocation_CultureTest()
+        {
+            var json = @"{
+  ""meta"": { ""code"": 200 },
+  ""response"": {
+    ""checkin"": {
+      ""id"": ""xxxxxxxxx"",
+      ""type"": ""checkin"",
+      ""venue"": {
+        ""id"": ""4b73dedcf964a5206bbe2de3"",
+        ""name"": ""高松駅 (Takamatsu Sta.)"",
+        ""location"": {
+          ""lat"": 34.35067978344854,
+          ""lng"": 134.04693603515625
+        }
+      }
+    }
+  }
+}";
+            var origCulture = Thread.CurrentThread.CurrentCulture;
+            Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
+
+            var jsonBytes = Encoding.UTF8.GetBytes(json);
+            var location = FoursquareCheckin.ParseIntoLocation(jsonBytes);
+
+            Thread.CurrentThread.CurrentCulture = origCulture;
+
+            Assert.NotNull(location);
+            Assert.Equal(34.35067978344854, location.Latitude);
+            Assert.Equal(134.04693603515625, location.Longitude);
+        }
+
+        [Fact]
         public void ParseInLocation_PlanetTest()
         {
             var json = @"{
index b60729a..2d740c0 100644 (file)
@@ -1,6 +1,7 @@
 更新履歴
 
 ==== Ver 1.3.7-dev(2016/xx/xx)
+ * FIX: OSの設定で小数点にピリオド以外の記号を用いている環境で、Foursquareのサムネイル表示時にエラーが発生する不具合を修正 (thx @Xiatian!)
 
 ==== Ver 1.3.6(2016/11/22)
  * NEW: 画像アップロード時のタイムアウト時間が変更できるようになりました
index 9b7caff..9ed5b58 100644 (file)
@@ -21,6 +21,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Globalization;
 using System.Net.Http;
 using System.Runtime.Serialization.Json;
 using System.Text.RegularExpressions;
@@ -195,8 +196,8 @@ namespace OpenTween.Thumbnail.Services
 
                 return new GlobalLocation
                 {
-                    Latitude = double.Parse(locationElm.Element("lat").Value),
-                    Longitude = double.Parse(locationElm.Element("lng").Value),
+                    Latitude = double.Parse(locationElm.Element("lat").Value, CultureInfo.InvariantCulture),
+                    Longitude = double.Parse(locationElm.Element("lng").Value, CultureInfo.InvariantCulture),
                 };
             }
         }