diff --git a/src/RestSharp/Authenticators/OAuth/OAuthTools.cs b/src/RestSharp/Authenticators/OAuth/OAuthTools.cs index f48400fbc..462e0bf88 100644 --- a/src/RestSharp/Authenticators/OAuth/OAuthTools.cs +++ b/src/RestSharp/Authenticators/OAuth/OAuthTools.cs @@ -142,7 +142,7 @@ public static string GetNonce() { internal static IEnumerable SortParametersExcludingSignature(WebPairCollection parameters) => parameters .Where(x => !x.Name.EqualsIgnoreCase("oauth_signature")) - .Select(x => new WebPair(UrlEncodeStrict(x.Name), UrlEncodeStrict(x.Value))) + .Select(x => new WebPair(UrlEncodeStrict(x.Name), UrlEncodeRelaxed(x.Value))) .OrderBy(x => x, WebPair.Comparer) .Select(x => x.GetQueryParameter(false)); diff --git a/test/RestSharp.Tests.Integrated/OAuth1Tests.cs b/test/RestSharp.Tests.Integrated/OAuth1Tests.cs index b81fd4d51..04827b1f8 100644 --- a/test/RestSharp.Tests.Integrated/OAuth1Tests.cs +++ b/test/RestSharp.Tests.Integrated/OAuth1Tests.cs @@ -51,17 +51,29 @@ public async Task Can_Authenticate_OAuth1_With_Querystring_Parameters() { actual.Should().BeEquivalentTo(expected); } - [Fact] - public void Properly_Encodes_Parameter_Names() { - var postData = new WebPairCollection { - { "name[first]", "Chuck" }, - { "name[last]", "Testa" } - }; + [Theory] + [MemberData(nameof(EncodeParametersTestData))] + public void Properly_Encodes_Parameter_Names(IList<(string, string)> parameters, string expected) { + var postData = new WebPairCollection(); + postData.AddRange(parameters.Select(x => new WebPair(x.Item1, x.Item2))); var sortedParams = OAuthTools.SortParametersExcludingSignature(postData); - sortedParams.First().Should().Be("name%5Bfirst%5D=Chuck"); + sortedParams.First().Should().Be(expected); } + public static IEnumerable EncodeParametersTestData => + new List + { + new object[] { + new List<(string, string)> { ("name[first]", "Chuck"), ("name[last]", "Testa") }, + "name%5Bfirst%5D=Chuck" + }, + new object[] { + new List<(string, string)> { ("country", "EspaƱa") }, + "country=Espa%C3%B1a" + } + }; + [Fact] public void Use_RFC_3986_Encoding_For_Auth_Signature_Base() { // reserved characters for 2396 and 3986