diff --git a/CHANGELOG.md b/CHANGELOG.md index 2752e91..a9c5a17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,4 +12,10 @@ ### 🛠 Technical -- Minor bug fixes on tools (CI, csproj, etc...) \ No newline at end of file +- Minor bug fixes on tools (CI, csproj, etc...) + +## 202 + +### 🐛 Bug Fixes + +- Fixed a bug where the entire query string was encoded instead of only the query parameter keys and values. \ No newline at end of file diff --git a/NotoriousClient.Tests.Unit/RequestBuilderURIUnitTests.cs b/NotoriousClient.Tests.Unit/RequestBuilderURIUnitTests.cs index 5738c05..39bd9eb 100644 --- a/NotoriousClient.Tests.Unit/RequestBuilderURIUnitTests.cs +++ b/NotoriousClient.Tests.Unit/RequestBuilderURIUnitTests.cs @@ -1,4 +1,4 @@ -using NotoriousClient.Builder; +using NotoriousClient.Builder; using NotoriousClient.Tests.Unit.Attributes; namespace NotoriousClient.Tests.Unit @@ -6,8 +6,8 @@ namespace NotoriousClient.Tests.Unit public class RequestBuilderURIUnitTests { #region URI - [GWTFact(given: "a url, an endpoint, and an HTTP Verb", - when: "i build a request", + [GWTFact(given: "a url, an endpoint, and an HTTP Verb", + when: "i build a request", then: "request has right url, endpoint and verb")] public void RequestBuilder_Should_HaveRightUrlEndpointAndVerb() { @@ -15,11 +15,11 @@ public void RequestBuilder_Should_HaveRightUrlEndpointAndVerb() Endpoint endpoint = new Endpoint("/pandas", Method.Get); RequestBuilder requestBuilder = new RequestBuilder(url, endpoint); - HttpRequestMessage request = requestBuilder.Build(); + HttpRequestMessage request = requestBuilder.Build(); Assert.Equal(HttpMethod.Get, request.Method); Assert.NotNull(request.RequestUri); - Assert.Equal("https://toto.com/pandas", request.RequestUri!.ToString()); + Assert.Equal("https://toto.com/pandas", request.RequestUri.AbsoluteUri); } [GWTFact(given: "a url with and end slash, an endpoint with a start slash, and an HTTP Verb", @@ -35,7 +35,7 @@ public void RequestBuilder_Should_HandleUrlSlashProperly() Assert.Equal(HttpMethod.Get, request.Method); Assert.NotNull(request.RequestUri); - Assert.Equal("https://toto.com/pandas", request.RequestUri!.ToString()); + Assert.Equal("https://toto.com/pandas", request.RequestUri.AbsoluteUri); } [GWTFact(given: "a url, an endpoint, and an HTTP Verb", @@ -51,7 +51,7 @@ public void RequestBuilder_Should_AddUrlSlashProperly() Assert.Equal(HttpMethod.Get, request.Method); Assert.NotNull(request.RequestUri); - Assert.Equal("https://toto.com/pandas", request.RequestUri!.ToString()); + Assert.Equal("https://toto.com/pandas", request.RequestUri.AbsoluteUri); } #endregion @@ -70,7 +70,7 @@ public void RequestBuilder_Should_HaveOneQueryParams() Assert.Equal(HttpMethod.Get, request.Method); Assert.NotNull(request.RequestUri); - Assert.Equal("https://toto.com/pandas?toto%3dtoto", request.RequestUri!.ToString()); + Assert.Equal("https://toto.com/pandas?toto=toto", request.RequestUri.AbsoluteUri); } [GWTFact(given: "a request with two query parameters", @@ -88,7 +88,7 @@ public void RequestBuilder_Should_HaveTwoQueryParams() Assert.Equal(HttpMethod.Get, request.Method); Assert.NotNull(request.RequestUri); - Assert.Equal("https://toto.com/pandas?toto%3dtoto%26toto2%3dtoto2", request.RequestUri!.ToString()); + Assert.Equal("https://toto.com/pandas?toto=toto&toto2=toto2", request.RequestUri.AbsoluteUri); } #endregion @@ -107,7 +107,7 @@ public void RequestBuilder_Should_HandleEndpointParams() Assert.Equal(HttpMethod.Get, request.Method); Assert.NotNull(request.RequestUri); - Assert.Equal("https://toto.com/pandas/1", request.RequestUri!.ToString()); + Assert.Equal("https://toto.com/pandas/1", request.RequestUri.AbsoluteUri); } [GWTFact(given: "a request with one endpoint parameters and an endpoint without replacement token", diff --git a/NotoriousClient/Builder/RequestBuilder.Uri.cs b/NotoriousClient/Builder/RequestBuilder.Uri.cs index 95e8520..e96e4d2 100644 --- a/NotoriousClient/Builder/RequestBuilder.Uri.cs +++ b/NotoriousClient/Builder/RequestBuilder.Uri.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Specialized; -using System.Web; - -namespace NotoriousClient.Builder +namespace NotoriousClient.Builder { public partial class RequestBuilder : IRequestBuilder { @@ -83,13 +79,12 @@ private string HandleUriQueryParams(string uri, Dictionary query if (queryParams.Count > 0) { string queryParamsString = string.Join("&", queryParams.Select(kvp => string.Format("{0}={1}", kvp.Key, kvp.Value))); - return string.Format(uri + "?{0}", HttpUtility.UrlEncode(queryParamsString)); + return string.Format(uri + "?{0}", queryParamsString); } else { return uri; } - } private string HandleUriEndPointParams(string uri, Dictionary endPointParams) diff --git a/NotoriousClient/NotoriousClient.csproj b/NotoriousClient/NotoriousClient.csproj index 7ef9fad..1e1c83a 100644 --- a/NotoriousClient/NotoriousClient.csproj +++ b/NotoriousClient/NotoriousClient.csproj @@ -5,7 +5,7 @@ NotoriousClient enable enable - 2.0.1 + 2.0.2 README.md Brice SCHUMACHER https://github.com/Notorious-Coding/Notorious-Client/