From 564b544e65fa2a97d010785ced71fed6c3c1b51a Mon Sep 17 00:00:00 2001 From: Bobby Driggs Date: Tue, 2 Nov 2021 12:22:31 -0700 Subject: [PATCH 1/2] Update Utils to use Uri.EscapeDataString to properly URI encode query string parameters Update unit tests to reflect properly encoded URI, added email test case --- Recurly.Tests/UtilsTest.cs | 4 +++- Recurly/Utils.cs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Recurly.Tests/UtilsTest.cs b/Recurly.Tests/UtilsTest.cs index 14ee6d6c..b71bce39 100644 --- a/Recurly.Tests/UtilsTest.cs +++ b/Recurly.Tests/UtilsTest.cs @@ -29,8 +29,10 @@ public void QueryString() d.Add("decimal", 123.456m); d.Add("date", new DateTime(2020, 1, 1, 0, 0, 0, DateTimeKind.Utc)); d.Add("enum", Recurly.Tests.Constants.EnumValue.AllowedEnum); + d.Add("email", "testEmail@example.org"); + var result = Utils.QueryString(d); - Assert.Equal("?trueBool=true&falseBool=false&int=123&decimal=123.456&date=2020-01-01T00:00:00.000Z&enum=allowed_enum", result); + Assert.Equal("?trueBool=true&falseBool=false&int=123&decimal=123.456&date=2020-01-01T00%3A00%3A00.000Z&enum=allowed_enum&email=testEmail%40example.org", result); } } } diff --git a/Recurly/Utils.cs b/Recurly/Utils.cs index 3170586d..dda939f8 100644 --- a/Recurly/Utils.cs +++ b/Recurly/Utils.cs @@ -88,7 +88,8 @@ public static string QueryString(Dictionary queryParams) { stringRepr = param.Value.ToString(); } - qString.Add($"{param.Key}={Uri.EscapeUriString(stringRepr)}"); + + qString.Add($"{param.Key}={Uri.EscapeDataString(stringRepr)}"); } } From 0430ae5513a870ae7a05c5ec20773cc6e2f31596 Mon Sep 17 00:00:00 2001 From: Bobby Driggs Date: Wed, 3 Nov 2021 11:40:25 -0700 Subject: [PATCH 2/2] Update unit test, to test for properly encoded : character in timestamp --- Recurly.Tests/BaseClientTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Recurly.Tests/BaseClientTest.cs b/Recurly.Tests/BaseClientTest.cs index a2f0315f..6b80ff0b 100644 --- a/Recurly.Tests/BaseClientTest.cs +++ b/Recurly.Tests/BaseClientTest.cs @@ -78,10 +78,10 @@ public void WillAddQueryStringParameters() { var options = new RequestOptions(); options.AddHeader("Accept-Language", "en-US"); - var date = new DateTime(2020, 01, 01); + var date = DateTime.Parse("2020-01-01T08:00:00Z"); var paramsMatcher = MockClient.QueryParameterMatcher(new Dictionary { { "param_1", "param1" }, - { "param_2", Recurly.Utils.ISO8601(date) }, + { "param_2", "2020-01-01T08%3A00%3A00.000Z" }, }); var client = MockClient.Build(paramsMatcher, SuccessResponse(System.Net.HttpStatusCode.OK));