Skip to content

Commit b30a3fc

Browse files
committed
Fixed for Windows Phone not having Uri.HexEscape()
1 parent 33392e5 commit b30a3fc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

RestSharp/Authenticators/OAuth/OAuthTools.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public static string GetTimestamp(DateTime dateTime)
8989
/// <seealso cref="http://stackoverflow.com/questions/846487/how-to-get-uri-escapedatastring-to-comply-with-rfc-3986" />
9090
private static readonly string[] UriRfc3986CharsToEscape = new[] { "!", "*", "'", "(", ")" };
9191

92+
private static readonly string[] UriRfc3968EscapedHex = new[] {"%21", "%2A", "%27", "%28", "%29"};
93+
9294
/// <summary>
9395
/// URL encodes a string based on section 5.1 of the OAuth spec.
9496
/// Namely, percent encoding with [RFC3986], avoiding unreserved characters,
@@ -113,8 +115,10 @@ public static string UrlEncodeRelaxed(string value)
113115
StringBuilder escaped = new StringBuilder(Uri.EscapeDataString(value));
114116

115117
// Upgrade the escaping to RFC 3986, if necessary.
116-
for (int i = 0; i < UriRfc3986CharsToEscape.Length; i++) {
117-
escaped.Replace(UriRfc3986CharsToEscape[i], Uri.HexEscape(UriRfc3986CharsToEscape[i][0]));
118+
for (int i = 0; i < UriRfc3986CharsToEscape.Length; i++)
119+
{
120+
string t = UriRfc3986CharsToEscape[i];
121+
escaped.Replace(t, UriRfc3968EscapedHex[i]);
118122
}
119123

120124
// Return the fully-RFC3986-escaped string.

0 commit comments

Comments
 (0)