From dc8a160c7fbe3b22dfa3a4aa1b15191a353b18c6 Mon Sep 17 00:00:00 2001 From: RKrom Date: Sun, 14 Oct 2012 06:38:20 +0000 Subject: [PATCH] Finally fixed UrlEncode3986 to work with UTF-8, meaning that special characters are encoded for UTF-8. e.g. we can now upload files which have umlauts in their filename to Dropbox. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2142 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/OAuthHelper.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/GreenshotPlugin/Core/OAuthHelper.cs b/GreenshotPlugin/Core/OAuthHelper.cs index 971c8cff8..5f781294c 100644 --- a/GreenshotPlugin/Core/OAuthHelper.cs +++ b/GreenshotPlugin/Core/OAuthHelper.cs @@ -221,10 +221,10 @@ namespace GreenshotPlugin.Core { /// /// This is a different Url Encode implementation since the default .NET one outputs the percent encoding in lower case. /// While this is not a problem with the percent encoding spec, it is used in upper case throughout OAuth + /// The resulting string is for UTF-8 encoding! /// /// The value to Url encode - /// Returns a Url encoded string - /// This will cause an ignorable CA1055 warning in code analysis. + /// Returns a Url encoded string (unicode) with UTF-8 encoded % values public static string UrlEncode3986(string value) { StringBuilder result = new StringBuilder(); @@ -232,7 +232,10 @@ namespace GreenshotPlugin.Core { if (UNRESERVED_CHARS.IndexOf(symbol) != -1) { result.Append(symbol); } else { - result.Append('%' + String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0:X2}", (int)symbol)); + byte[] utf8Bytes = Encoding.UTF8.GetBytes(symbol.ToString()); + foreach(byte utf8Byte in utf8Bytes) { + result.AppendFormat("%{0:X2}", utf8Byte); + } } }