Skip to content

Commit

Permalink
Merge pull request #1121 from mscharrig/develop
Browse files Browse the repository at this point in the history
Fixes #1104
  • Loading branch information
alexeyzimarev committed May 17, 2018
2 parents 1805996 + c3e0e2f commit 398e546
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion RestSharp.IntegrationTests/oAuth1Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public void Use_RFC_3986_Encoding_For_Auth_Signature_Base()
var escapedString = OAuthTools.UrlEncodeRelaxed(reservedCharacterString);

// assert
Assert.AreEqual("%3B%2F%3F%3A%40%26%3D%2B%24%2C%21%2A%27%28%29", escapedString);
Assert.AreEqual("%3B%2F%3F%3A%40%26%3D%2B%24%2C%2521%252A%2527%2528%2529", escapedString);
}
}
}
16 changes: 7 additions & 9 deletions RestSharp/Authenticators/OAuth/OAuthTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,20 @@ public static string GetTimestamp(DateTime dateTime)
/// <seealso cref="http://stackoverflow.com/questions/846487/how-to-get-uri-escapedatastring-to-comply-with-rfc-3986" />
public static string UrlEncodeRelaxed(string value)
{
// Start with RFC 2396 escaping by calling the .NET method to do the work.
// This MAY sometimes exhibit RFC 3986 behavior (according to the documentation).
// If it does, the escaping we do that follows it will be a no-op since the
// characters we search for to replace can't possibly exist in the string.
var escaped = new StringBuilder(Uri.EscapeDataString(value));

// Upgrade the escaping to RFC 3986, if necessary.
// Escape RFC 3986 chars first.
var escapedRfc3986 = new StringBuilder(value);
for (var i = 0; i < uriRfc3986CharsToEscape.Length; i++)
{
var t = uriRfc3986CharsToEscape[i];

escaped.Replace(t, uriRfc3968EscapedHex[i]);
escapedRfc3986.Replace(t, uriRfc3968EscapedHex[i]);
}

// Do RFC 2396 escaping by calling the .NET method to do the work.
string escapedRfc2396 = Uri.EscapeDataString(escapedRfc3986.ToString());

// Return the fully-RFC3986-escaped string.
return escaped.ToString();
return escapedRfc2396;
}

/// <summary>
Expand Down

0 comments on commit 398e546

Please sign in to comment.