From: Kimura Youichi Date: Sat, 24 May 2014 04:17:29 +0000 (+0900) Subject: クエリの構築に HttpUtility.ParseQueryString() を使用している箇所を MyCommon.BuildQueryString() に置き換え... X-Git-Tag: OpenTween_v1.2.1~13 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=760fe1add6a9c23ce1e92bfcd8ddb53ade60cca7;p=opentween%2Fopen-tween.git クエリの構築に HttpUtility.ParseQueryString() を使用している箇所を MyCommon.BuildQueryString() に置き換え (thx @KishSoup!) HttpUtility.ParseQueryString() を使用してクエリを構築した場合に、 マルチバイト文字が「%u6d32」のような不適切な形にエスケープされてしまう問題への対処。 参照: https://twitter.com/KishSoup/status/468058259950026752 --- diff --git a/OpenTween/Bing.cs b/OpenTween/Bing.cs index 3d57cc4c..559cbfea 100644 --- a/OpenTween/Bing.cs +++ b/OpenTween/Bing.cs @@ -181,15 +181,18 @@ namespace OpenTween /// public async Task TranslateAsync(string text, string langFrom, string langTo) { - var param = HttpUtility.ParseQueryString(string.Empty); - param["Text"] = "'" + text + "'"; - param["To"] = "'" + langTo + "'"; - param["$format"] = "Raw"; + var param = new Dictionary + { + {"Text", "'" + text + "'"}, + {"To", "'" + langTo + "'"}, + {"$format", "Raw"}, + }; if (langFrom != null) param["From"] = "'" + langFrom + "'"; - var request = new HttpRequestMessage(HttpMethod.Get, TranslateUri + "?" + param); + var uri = new Uri(TranslateUri + "?" + MyCommon.BuildQueryString(param)); + var request = new HttpRequestMessage(HttpMethod.Get, uri); request.Headers.Authorization = CreateBasicAuthHeaderValue(ApplicationSettings.AzureMarketplaceKey, ApplicationSettings.AzureMarketplaceKey); using (var response = await this.http.SendAsync(request).ConfigureAwait(false)) diff --git a/OpenTween/Resources/ChangeLog.txt b/OpenTween/Resources/ChangeLog.txt index 43c1fc53..af1b5beb 100644 --- a/OpenTween/Resources/ChangeLog.txt +++ b/OpenTween/Resources/ChangeLog.txt @@ -4,6 +4,7 @@ * FIX: 発言詳細欄から右クリックで日本語ハッシュタグを固定すると、エンコード状態のハッシュタグが登録される問題を修正 * FIX: PublicSearchタブでの検索時に Err:Unauthorized(GetSearch) が表示される問題の回避策を追加 * FIX: サムネイル画像の読み込み中に別のツイートに選択を移動した際に動作が固まる現象の回避 (thx @_1t_, @Tan90909090, @suzushin!) + * FIX: 日本語等を含むツイートでBing翻訳機能を使用すると文字化けする問題を修正 (thx @KishSoup!) ==== Ver 1.2.0(2014/05/18) * このバージョン以降のOpenTweenは .NET Framework 4.5.1 が必要となります diff --git a/OpenTween/ShortUrl.cs b/OpenTween/ShortUrl.cs index bacda3e3..297aed3d 100644 --- a/OpenTween/ShortUrl.cs +++ b/OpenTween/ShortUrl.cs @@ -401,14 +401,17 @@ namespace OpenTween if (string.IsNullOrEmpty(this.BitlyId) || string.IsNullOrEmpty(this.BitlyKey)) return srcUri; - var query = HttpUtility.ParseQueryString(string.Empty); - query["login"] = this.BitlyId; - query["apiKey"] = this.BitlyKey; - query["format"] = "txt"; - query["domain"] = domain; - query["longUrl"] = srcUri.OriginalString; - - using (var response = await this.http.GetAsync("https://api-ssl.bitly.com/v3/shorten?" + query).ConfigureAwait(false)) + var query = new Dictionary + { + {"login", this.BitlyId}, + {"apiKey", this.BitlyKey}, + {"format", "txt"}, + {"domain", domain}, + {"longUrl", srcUri.OriginalString}, + }; + + var uri = new Uri("https://api-ssl.bitly.com/v3/shorten?" + MyCommon.BuildQueryString(query)); + using (var response = await this.http.GetAsync(uri).ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); @@ -428,11 +431,14 @@ namespace OpenTween if ("http://ux.nx/xxxxxx".Length > srcUri.OriginalString.Length) return srcUri; - var query = HttpUtility.ParseQueryString(string.Empty); - query["format"] = "plain"; - query["url"] = srcUri.OriginalString; + var query = new Dictionary + { + {"format", "plain"}, + {"url", srcUri.OriginalString}, + }; - using (var response = await this.http.GetAsync("http://ux.nu/api/short?" + query).ConfigureAwait(false)) + var uri = new Uri("http://ux.nu/api/short?" + MyCommon.BuildQueryString(query)); + using (var response = await this.http.GetAsync(uri).ConfigureAwait(false)) { response.EnsureSuccessStatusCode(); diff --git a/OpenTween/Thumbnail/Services/FoursquareCheckin.cs b/OpenTween/Thumbnail/Services/FoursquareCheckin.cs index c98bb03c..4ae2f26a 100644 --- a/OpenTween/Thumbnail/Services/FoursquareCheckin.cs +++ b/OpenTween/Thumbnail/Services/FoursquareCheckin.cs @@ -20,6 +20,7 @@ // Boston, MA 02110-1301, USA. using System; +using System.Collections.Generic; using System.Net.Http; using System.Runtime.Serialization.Json; using System.Text.RegularExpressions; @@ -65,15 +66,17 @@ namespace OpenTween.Thumbnail.Services // Foursquare のベニュー情報を取得 // 参照: https://developer.foursquare.com/docs/venues/venues - var query = HttpUtility.ParseQueryString(string.Empty); - query["client_id"] = ApplicationSettings.FoursquareClientId; - query["client_secret"] = ApplicationSettings.FoursquareClientSecret; - query["v"] = "20140419"; // https://developer.foursquare.com/overview/versioning + var query = new Dictionary + { + {"client_id", ApplicationSettings.FoursquareClientId}, + {"client_secret", ApplicationSettings.FoursquareClientSecret}, + {"v", "20140419"}, // https://developer.foursquare.com/overview/versioning + }; if (signatureGroup.Success) query["signature"] = signatureGroup.Value; - var apiUrl = new Uri(ApiBase + "/checkins/" + checkinIdGroup.Value + "?" + query); + var apiUrl = new Uri(ApiBase + "/checkins/" + checkinIdGroup.Value + "?" + MyCommon.BuildQueryString(query)); using (var response = await this.http.GetAsync(apiUrl, token).ConfigureAwait(false)) { diff --git a/OpenTween/Thumbnail/Services/Tinami.cs b/OpenTween/Thumbnail/Services/Tinami.cs index 22ef1df1..df7c569b 100644 --- a/OpenTween/Thumbnail/Services/Tinami.cs +++ b/OpenTween/Thumbnail/Services/Tinami.cs @@ -81,11 +81,13 @@ namespace OpenTween.Thumbnail.Services protected virtual async Task FetchContentInfoApiAsync(string contentId, CancellationToken token) { - var query = HttpUtility.ParseQueryString(string.Empty); - query["api_key"] = ApplicationSettings.TINAMIApiKey; - query["cont_id"] = contentId; + var query = new Dictionary + { + {"api_key", ApplicationSettings.TINAMIApiKey}, + {"cont_id", contentId}, + }; - var apiUrl = "http://api.tinami.com/content/info?" + query; + var apiUrl = new Uri("http://api.tinami.com/content/info?" + MyCommon.BuildQueryString(query)); using (var response = await this.http.GetAsync(apiUrl, token).ConfigureAwait(false)) {