From 4bd9eac2066f6384e1fc2bb29f5152b97a2d59d6 Mon Sep 17 00:00:00 2001 From: Alexey Zimarev Date: Sun, 25 Jan 2026 13:26:14 +0100 Subject: [PATCH 1/4] Fix #2207: Prevent Uri constructor from re-encoding pipe character when encode=false The issue was that when AddQueryParameter was called with encode=false, the pipe character (|) was still being encoded to %7C. This happened because the AddQueryString method was creating a new Uri object directly, and the Uri constructor automatically encodes certain characters including the pipe character. The fix uses UriBuilder instead, which preserves the query string as-is without re-encoding it. This ensures that when encode=false is specified, characters like pipe (|) remain unencoded as expected. Added test case to verify pipe character is not encoded when encode=false. --- .DS_Store | Bin 0 -> 8196 bytes src/RestSharp/Request/UriExtensions.cs | 8 +++++--- test/.DS_Store | Bin 0 -> 6148 bytes test/RestSharp.Tests/UrlBuilderTests.Get.cs | 12 ++++++++++++ 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 .DS_Store create mode 100644 test/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..d05a773ac36c77c34611137da01ed142f212d0e7 GIT binary patch literal 8196 zcmeHMTWl0n7(U;$z|25lid;IY(4`xMlp<}V+>xc*npR3$d!ZLD>+a47BeOGQXLc89 znl#2s0vMk}_ zR1tX~@<8N)$ODlFA`jdR9-uv&CwY#2U$jPfmJiJv(k&p5NSj1yWV@y!i{{1@c1q@W3&*Jm6>i zqSu}&9OTlV>)P2$Ig>qLndP*$Eaf_W#&XO;U|<<0sT>-%9K$WQyG6(F0^0%6AS<$x z*6JoEwzW1l#kaP#O*X|Rw)67lhqp{lD)REgrk(xi<96P0Pm3ua{0y*~SyMVQb3V3L zN{Rc3suh*_T&>JUQ5Wh5hSkv#E9W``)+sZsE%9hV-6ZxE%o0sxIOp2MyyK;{+FZuY z743{~?zL^M?2Y*5NuQU-Jh$Md0>!kZ6+N@xBt5HSc91riF6BM-j{BDDcn8daN0>-9 zi`P~zELy&*;lT~fZ9Dd)x_bI9*DPM5)h<=lG4hP#TTfbMVW?~w{;|=Fmopv1a*hs{ zEYHf?=Ae_wo3+@jD3@2PtgF#u`U91w*(S1qOD=pAN=YU9YQ$40^%+uE9q! zw2QJ5v?S_v{UC2i6->$vSq`e#t=H8-kEW|-LdB+ysycX_mQ?fT75Iy{w5s}$oynTE zW+=jJ%T`q%E{R!d`@+hdyHtH7=jQV?MXwf3VRe#5KEg-t$#{P6xamv}-qES+W8Se$ z!R##)r?gMQm+GeaVAZIF8+96%?-r;ra7ex0E6bz2!@Y)K8kcKU)~$HFpIc~_Q?iJ~ zv=oBO+PAVSCz6d~RRYf{%Vsf)?@&5xV4K-4*2hLEX3Fd=dzqbMZ?g;RBlZdVjD5qd zuxso)_C5QFU1z_sKiOaGZ!joWih8U;0}^P$Hf+ZZq|k-Oun#>L!Wa(WFpl6T@^CSZ z6F7xu@GPFg^LPob;&r@%H}MWG;(dI8OZXgL;wyZOtM~=K;yQlEAGjewQl(W=y%d+$ zNDa~ksac{MKAxmXw2TS4l1uGWnvQ;omhkpY%HJ+pVx5nwUH@yeTw5gK(Fx+&J8Py}gJLTrq+DY6D3Y*TkA6iZsQ5O=G46dv9h z3*=a1EG5g@zo6-P_8wi!USeMmO@ClNvY*)vqNa?+sKaWaCnx7xJcLbXK`S<6Hy%L} zdx@w$*pFWHp&ti{s7H`S22bHQY&a<6B$0IjlSI`Qa2jXuBF^CzBJFEL+qZBY?+Ut2 zld!u&KY{poCJ9Re1;=)sqf}QR?ak_ubjLhUC3>pk=l{;R@Bi=Ecu_}@2OR7a2zKLj^l*We;86ZPO97{8RC>cs-g6sUj)#P P-Dv-h_Wyu<_i*+PxSJ1P literal 0 HcmV?d00001 diff --git a/src/RestSharp/Request/UriExtensions.cs b/src/RestSharp/Request/UriExtensions.cs index 9cb26ebe8..3148ae426 100644 --- a/src/RestSharp/Request/UriExtensions.cs +++ b/src/RestSharp/Request/UriExtensions.cs @@ -41,10 +41,12 @@ public static Uri MergeBaseUrlAndResource(this Uri? baseUrl, string? resource) { public static Uri AddQueryString(this Uri uri, string? query) { if (query == null) return uri; - var absoluteUri = uri.AbsoluteUri; - var separator = absoluteUri.Contains('?') ? "&" : "?"; + var builder = new UriBuilder(uri); + builder.Query = builder.Query.Length > 1 + ? builder.Query[1..] + "&" + query + : query; - return new($"{absoluteUri}{separator}{query}"); + return builder.Uri; } public static UrlSegmentParamsValues GetUrlSegmentParamsValues( diff --git a/test/.DS_Store b/test/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b6ef5b4ab8240145247fb973c412350b89b46a3d GIT binary patch literal 6148 zcmeH~&q@O^5XL9AhpN@qn+L%lcoljVT`Xp1c}1Id@2%_Nf_-J~HRRXuA|h{{A%Kw-^Kq58!5J(nJvaGoMm znK2@2(mu7RMJqkM#UTWQz_=0MZ?{A{bVwaKCI9=~b-qq~REZAKq{XS1&Wp*<5lI?` z^*F7gXW@BcyLnN5T>ni}qmQUo)64FO_c7AnuLpZmgtfKl7<*NW`qDgg;NJp;lurB= z&)(gx4P#87Np0a~dFJJTnGBq3l73Jd=D1y4CpA)~#lE@jQ9`j#HFtGAH~5G?)77Q- z-`Rk9`b38}s?Rfb|H?c^ZOSH4m>zW^GQSWI0%J#j_Xmx_8aU0YnymwsxdK4*a2rG0 zoWW4d4rt&svkDJP*-)qrRql$RY&iVd^$VP4R&6*bGc(3 z5CYu Assert.Throws(() => { _ = new RestClient("invalid url"); } From 87cbd077bdc9e673e70c958fa8eb85eb059e8832 Mon Sep 17 00:00:00 2001 From: Alexey Zimarev Date: Sun, 25 Jan 2026 15:59:54 +0100 Subject: [PATCH 2/4] Fix issue #2207: Preserve unencoded characters in query parameters when encode=false - Modified BuildUriExtensions to add BuildUriString method that returns a string URI - Updated RestClient.Async to use string URI for HttpRequestMessage to preserve unencoded characters - Added RawUrl property to RequestBodyCapturer to capture the actual URL string sent over HTTP - Added integration test to verify pipe character is not encoded when encode=false - All existing tests pass --- src/RestSharp/BuildUriExtensions.cs | 25 +++++++++++++++++++ src/RestSharp/Request/UriExtensions.cs | 4 +-- src/RestSharp/RestClient.Async.cs | 3 ++- .../DefaultParameterTests.cs | 13 ++++++++++ .../Fixtures/RequestBodyCapturer.cs | 2 ++ 5 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/RestSharp/BuildUriExtensions.cs b/src/RestSharp/BuildUriExtensions.cs index 6bf976244..6ee360f40 100644 --- a/src/RestSharp/BuildUriExtensions.cs +++ b/src/RestSharp/BuildUriExtensions.cs @@ -37,6 +37,31 @@ public Uri BuildUri(RestRequest request) { return mergedUri.AddQueryString(query); } + /// + /// Builds the URI string for the request. This method returns a string instead of a Uri object + /// to preserve unencoded characters when encode=false is specified for query parameters. + /// + /// Request instance + /// + [PublicAPI] + public string BuildUriString(RestRequest request) { + DoBuildUriValidations(client, request); + + var (uri, resource) = client.Options.BaseUrl.GetUrlSegmentParamsValues( + request.Resource, + client.Options.Encode, + request.Parameters, + client.DefaultParameters + ); + var mergedUri = uri.MergeBaseUrlAndResource(resource); + var query = client.GetRequestQuery(request); + + if (query == null) return mergedUri.AbsoluteUri; + + var separator = mergedUri.AbsoluteUri.Contains('?') ? "&" : "?"; + return $"{mergedUri.AbsoluteUri}{separator}{query}"; + } + /// /// Builds the URI for the request without query parameters. /// diff --git a/src/RestSharp/Request/UriExtensions.cs b/src/RestSharp/Request/UriExtensions.cs index 3148ae426..bc217dff6 100644 --- a/src/RestSharp/Request/UriExtensions.cs +++ b/src/RestSharp/Request/UriExtensions.cs @@ -42,9 +42,7 @@ public static Uri AddQueryString(this Uri uri, string? query) { if (query == null) return uri; var builder = new UriBuilder(uri); - builder.Query = builder.Query.Length > 1 - ? builder.Query[1..] + "&" + query - : query; + builder.Query = builder.Query.Length > 1 ? $"{builder.Query[1..]}&{query}" : query; return builder.Uri; } diff --git a/src/RestSharp/RestClient.Async.cs b/src/RestSharp/RestClient.Async.cs index 75c8ac85f..e02b24100 100644 --- a/src/RestSharp/RestClient.Async.cs +++ b/src/RestSharp/RestClient.Async.cs @@ -112,8 +112,9 @@ async Task ExecuteRequestAsync(RestRequest request, CancellationTo var httpMethod = AsHttpMethod(request.Method); var url = this.BuildUri(request); + var urlString = this.BuildUriString(request); - using var message = new HttpRequestMessage(httpMethod, url); + using var message = new HttpRequestMessage(httpMethod, urlString); message.Content = requestContent.BuildContent(); message.Headers.Host = Options.BaseHost; message.Headers.CacheControl = request.CachePolicy ?? Options.CachePolicy; diff --git a/test/RestSharp.Tests.Integrated/DefaultParameterTests.cs b/test/RestSharp.Tests.Integrated/DefaultParameterTests.cs index f61c5a55d..c2038f6a3 100644 --- a/test/RestSharp.Tests.Integrated/DefaultParameterTests.cs +++ b/test/RestSharp.Tests.Integrated/DefaultParameterTests.cs @@ -35,4 +35,17 @@ public async Task Should_not_throw_exception_when_name_is_null() { await client.ExecuteAsync(request); } + + [Fact] + public async Task Should_not_encode_pipe_character_when_encode_is_false() { + using var client = new RestClient(server.Url!); + + var request = new RestRequest("capture"); + request.AddQueryParameter("ids", "in:001|116", false); + + await client.ExecuteAsync(request); + + var query = _capturer.RawUrl.Split('?')[1]; + query.Should().Contain("ids=in:001|116"); + } } \ No newline at end of file diff --git a/test/RestSharp.Tests.Shared/Fixtures/RequestBodyCapturer.cs b/test/RestSharp.Tests.Shared/Fixtures/RequestBodyCapturer.cs index cc9ead4fb..cca83ff9c 100644 --- a/test/RestSharp.Tests.Shared/Fixtures/RequestBodyCapturer.cs +++ b/test/RestSharp.Tests.Shared/Fixtures/RequestBodyCapturer.cs @@ -7,6 +7,7 @@ public class RequestBodyCapturer { public bool HasBody { get; private set; } public string Body { get; private set; } public Uri Url { get; private set; } + public string RawUrl { get; private set; } public bool CaptureBody(string content) { Body = content; @@ -23,6 +24,7 @@ public bool CaptureHeaders(IDictionary headers) { } public bool CaptureUrl(string url) { + RawUrl = url; Url = new(url); return true; } From 1fb62036deeefec8ebd102bae09bd7f00007c9bb Mon Sep 17 00:00:00 2001 From: Alexey Zimarev Date: Sun, 25 Jan 2026 16:11:05 +0100 Subject: [PATCH 3/4] Fix pipe encoding issue --- .DS_Store | Bin 8196 -> 0 bytes src/RestSharp/BuildUriExtensions.cs | 24 ++------------------ src/RestSharp/RestClient.Async.cs | 2 +- test/.DS_Store | Bin 6148 -> 0 bytes test/RestSharp.Tests/UrlBuilderTests.Get.cs | 4 ++-- 5 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 .DS_Store delete mode 100644 test/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index d05a773ac36c77c34611137da01ed142f212d0e7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMTWl0n7(U;$z|25lid;IY(4`xMlp<}V+>xc*npR3$d!ZLD>+a47BeOGQXLc89 znl#2s0vMk}_ zR1tX~@<8N)$ODlFA`jdR9-uv&CwY#2U$jPfmJiJv(k&p5NSj1yWV@y!i{{1@c1q@W3&*Jm6>i zqSu}&9OTlV>)P2$Ig>qLndP*$Eaf_W#&XO;U|<<0sT>-%9K$WQyG6(F0^0%6AS<$x z*6JoEwzW1l#kaP#O*X|Rw)67lhqp{lD)REgrk(xi<96P0Pm3ua{0y*~SyMVQb3V3L zN{Rc3suh*_T&>JUQ5Wh5hSkv#E9W``)+sZsE%9hV-6ZxE%o0sxIOp2MyyK;{+FZuY z743{~?zL^M?2Y*5NuQU-Jh$Md0>!kZ6+N@xBt5HSc91riF6BM-j{BDDcn8daN0>-9 zi`P~zELy&*;lT~fZ9Dd)x_bI9*DPM5)h<=lG4hP#TTfbMVW?~w{;|=Fmopv1a*hs{ zEYHf?=Ae_wo3+@jD3@2PtgF#u`U91w*(S1qOD=pAN=YU9YQ$40^%+uE9q! zw2QJ5v?S_v{UC2i6->$vSq`e#t=H8-kEW|-LdB+ysycX_mQ?fT75Iy{w5s}$oynTE zW+=jJ%T`q%E{R!d`@+hdyHtH7=jQV?MXwf3VRe#5KEg-t$#{P6xamv}-qES+W8Se$ z!R##)r?gMQm+GeaVAZIF8+96%?-r;ra7ex0E6bz2!@Y)K8kcKU)~$HFpIc~_Q?iJ~ zv=oBO+PAVSCz6d~RRYf{%Vsf)?@&5xV4K-4*2hLEX3Fd=dzqbMZ?g;RBlZdVjD5qd zuxso)_C5QFU1z_sKiOaGZ!joWih8U;0}^P$Hf+ZZq|k-Oun#>L!Wa(WFpl6T@^CSZ z6F7xu@GPFg^LPob;&r@%H}MWG;(dI8OZXgL;wyZOtM~=K;yQlEAGjewQl(W=y%d+$ zNDa~ksac{MKAxmXw2TS4l1uGWnvQ;omhkpY%HJ+pVx5nwUH@yeTw5gK(Fx+&J8Py}gJLTrq+DY6D3Y*TkA6iZsQ5O=G46dv9h z3*=a1EG5g@zo6-P_8wi!USeMmO@ClNvY*)vqNa?+sKaWaCnx7xJcLbXK`S<6Hy%L} zdx@w$*pFWHp&ti{s7H`S22bHQY&a<6B$0IjlSI`Qa2jXuBF^CzBJFEL+qZBY?+Ut2 zld!u&KY{poCJ9Re1;=)sqf}QR?ak_ubjLhUC3>pk=l{;R@Bi=Ecu_}@2OR7a2zKLj^l*We;86ZPO97{8RC>cs-g6sUj)#P P-Dv-h_Wyu<_i*+PxSJ1P diff --git a/src/RestSharp/BuildUriExtensions.cs b/src/RestSharp/BuildUriExtensions.cs index 6ee360f40..8fb95563e 100644 --- a/src/RestSharp/BuildUriExtensions.cs +++ b/src/RestSharp/BuildUriExtensions.cs @@ -23,19 +23,7 @@ public static class BuildUriExtensions { /// /// Request instance /// - public Uri BuildUri(RestRequest request) { - DoBuildUriValidations(client, request); - - var (uri, resource) = client.Options.BaseUrl.GetUrlSegmentParamsValues( - request.Resource, - client.Options.Encode, - request.Parameters, - client.DefaultParameters - ); - var mergedUri = uri.MergeBaseUrlAndResource(resource); - var query = client.GetRequestQuery(request); - return mergedUri.AddQueryString(query); - } + public Uri BuildUri(RestRequest request) => new(client.BuildUriString(request)); /// /// Builds the URI string for the request. This method returns a string instead of a Uri object @@ -45,15 +33,7 @@ public Uri BuildUri(RestRequest request) { /// [PublicAPI] public string BuildUriString(RestRequest request) { - DoBuildUriValidations(client, request); - - var (uri, resource) = client.Options.BaseUrl.GetUrlSegmentParamsValues( - request.Resource, - client.Options.Encode, - request.Parameters, - client.DefaultParameters - ); - var mergedUri = uri.MergeBaseUrlAndResource(resource); + var mergedUri = client.BuildUriWithoutQueryParameters(request); var query = client.GetRequestQuery(request); if (query == null) return mergedUri.AbsoluteUri; diff --git a/src/RestSharp/RestClient.Async.cs b/src/RestSharp/RestClient.Async.cs index e02b24100..df4558795 100644 --- a/src/RestSharp/RestClient.Async.cs +++ b/src/RestSharp/RestClient.Async.cs @@ -111,8 +111,8 @@ async Task ExecuteRequestAsync(RestRequest request, CancellationTo using var requestContent = new RequestContent(this, request); var httpMethod = AsHttpMethod(request.Method); - var url = this.BuildUri(request); var urlString = this.BuildUriString(request); + var url = new Uri(urlString); using var message = new HttpRequestMessage(httpMethod, urlString); message.Content = requestContent.BuildContent(); diff --git a/test/.DS_Store b/test/.DS_Store deleted file mode 100644 index b6ef5b4ab8240145247fb973c412350b89b46a3d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~&q@O^5XL9AhpN@qn+L%lcoljVT`Xp1c}1Id@2%_Nf_-J~HRRXuA|h{{A%Kw-^Kq58!5J(nJvaGoMm znK2@2(mu7RMJqkM#UTWQz_=0MZ?{A{bVwaKCI9=~b-qq~REZAKq{XS1&Wp*<5lI?` z^*F7gXW@BcyLnN5T>ni}qmQUo)64FO_c7AnuLpZmgtfKl7<*NW`qDgg;NJp;lurB= z&)(gx4P#87Np0a~dFJJTnGBq3l73Jd=D1y4CpA)~#lE@jQ9`j#HFtGAH~5G?)77Q- z-`Rk9`b38}s?Rfb|H?c^ZOSH4m>zW^GQSWI0%J#j_Xmx_8aU0YnymwsxdK4*a2rG0 zoWW4d4rt&svkDJP*-)qrRql$RY&iVd^$VP4R&6*bGc(3 z5CYu Date: Mon, 26 Jan 2026 15:41:28 +0100 Subject: [PATCH 4/4] Remove usage of BuildUrl --- .../OAuth/OAuth1Authenticator.cs | 2 +- .../AuthenticationTests.cs | 3 +-- .../Auth/OAuth1SignatureTests.cs | 2 +- test/RestSharp.Tests/Auth/OAuth1Tests.cs | 2 +- .../Parameters/UrlSegmentTests.cs | 26 ++++++++++--------- test/RestSharp.Tests/RestRequestTests.cs | 4 +-- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/RestSharp/Authenticators/OAuth/OAuth1Authenticator.cs b/src/RestSharp/Authenticators/OAuth/OAuth1Authenticator.cs index f69f5ff39..56906120f 100644 --- a/src/RestSharp/Authenticators/OAuth/OAuth1Authenticator.cs +++ b/src/RestSharp/Authenticators/OAuth/OAuth1Authenticator.cs @@ -245,7 +245,7 @@ internal static void AddOAuthData( "Using query parameters in the base URL is not supported for OAuth calls. Consider using AddDefaultQueryParameter instead." ); - var url = client.BuildUri(request).ToString(); + var url = client.BuildUriString(request); var queryStringStart = url.IndexOf('?'); if (queryStringStart != -1) url = url[..queryStringStart]; diff --git a/test/RestSharp.InteractiveTests/AuthenticationTests.cs b/test/RestSharp.InteractiveTests/AuthenticationTests.cs index 7e5d81173..72754b1a8 100644 --- a/test/RestSharp.InteractiveTests/AuthenticationTests.cs +++ b/test/RestSharp.InteractiveTests/AuthenticationTests.cs @@ -39,8 +39,7 @@ public static async Task Can_Authenticate_With_OAuth_Async_With_Callback(Twitter request = new($"oauth/authorize?oauth_token={oauthToken}"); - var url = client.BuildUri(request) - .ToString(); + var url = client.BuildUriString(request); Console.WriteLine($"Open this URL in the browser: {url} and complete the authentication."); Console.Write("Enter the verifier: "); diff --git a/test/RestSharp.Tests/Auth/OAuth1SignatureTests.cs b/test/RestSharp.Tests/Auth/OAuth1SignatureTests.cs index 782a7a121..f23f411c5 100644 --- a/test/RestSharp.Tests/Auth/OAuth1SignatureTests.cs +++ b/test/RestSharp.Tests/Auth/OAuth1SignatureTests.cs @@ -37,7 +37,7 @@ public void Generates_correct_signature_base() { var requestParameters = _request.Parameters.ToWebParameters().ToArray(); var parameters = new WebPairCollection(); parameters.AddRange(requestParameters); - var url = _client.BuildUri(_request).ToString(); + var url = _client.BuildUriString(_request); _workflow.RequestUrl = url; var oauthParameters = _workflow.BuildProtectedResourceSignature(method, parameters); oauthParameters.Parameters.AddRange(requestParameters); diff --git a/test/RestSharp.Tests/Auth/OAuth1Tests.cs b/test/RestSharp.Tests/Auth/OAuth1Tests.cs index 483a89771..8f4356cf6 100644 --- a/test/RestSharp.Tests/Auth/OAuth1Tests.cs +++ b/test/RestSharp.Tests/Auth/OAuth1Tests.cs @@ -46,7 +46,7 @@ public async Task Can_Authenticate_OAuth1_With_Querystring_Parameters() { authenticator.ParameterHandling = OAuthParameterHandling.UrlOrPostParameters; await authenticator.Authenticate(client, request); - var requestUri = client.BuildUri(request); + var requestUri = new Uri(client.BuildUriString(request)); var actual = requestUri.ParseQuery().Select(x => x.Key).ToList(); actual.Should().BeEquivalentTo(expected); diff --git a/test/RestSharp.Tests/Parameters/UrlSegmentTests.cs b/test/RestSharp.Tests/Parameters/UrlSegmentTests.cs index 5282dc57c..d7358a333 100644 --- a/test/RestSharp.Tests/Parameters/UrlSegmentTests.cs +++ b/test/RestSharp.Tests/Parameters/UrlSegmentTests.cs @@ -1,7 +1,8 @@ namespace RestSharp.Tests.Parameters; public class UrlSegmentTests { - const string BaseUrl = "http://localhost:8888/"; + const string BaseUrlNoTrail = "http://localhost:8888"; + const string BaseUrl = $"{BaseUrlNoTrail}/"; [Fact] public void AddUrlSegmentWithInt() { @@ -22,10 +23,10 @@ public void AddUrlSegmentModifiesUrlSegmentWithInt() { var path = string.Format(pathTemplate, $"{{{name}}}"); var request = new RestRequest(path).AddUrlSegment(name, urlSegmentValue); - var expected = string.Format(pathTemplate, urlSegmentValue); + var expected = $"{BaseUrlNoTrail}{string.Format(pathTemplate, urlSegmentValue)}"; using var client = new RestClient(BaseUrl); - var actual = client.BuildUri(request).AbsolutePath; + var actual = client.BuildUriString(request); expected.Should().BeEquivalentTo(actual); } @@ -38,11 +39,11 @@ public void AddUrlSegmentModifiesUrlSegmentWithString() { var path = string.Format(pathTemplate, $"{{{name}}}"); var request = new RestRequest(path).AddUrlSegment(name, urlSegmentValue); - var expected = string.Format(pathTemplate, urlSegmentValue); + var expected = $"{BaseUrlNoTrail}{string.Format(pathTemplate, urlSegmentValue)}"; using var client = new RestClient(BaseUrl); - var actual = client.BuildUri(request).AbsolutePath; + var actual = client.BuildUriString(request); expected.Should().BeEquivalentTo(actual); } @@ -73,14 +74,15 @@ public void UrlSegmentParameter_WithValueWithEncodedSlash_CanLeaveEncodedSlash(s [Fact] public void AddSameUrlSegmentTwice_ShouldReplaceFirst() { - var client = new RestClient(); - var request = new RestRequest("https://api.example.com/orgs/{segment}/something"); + const string host = "https://api.example.com"; + var client = new RestClient(); + var request = new RestRequest($"{host}/orgs/{{segment}}/something"); request.AddUrlSegment("segment", 1); - var url1 = client.BuildUri(request); + var url1 = client.BuildUriString(request); request.AddUrlSegment("segment", 2); - var url2 = client.BuildUri(request); - - url1.AbsolutePath.Should().Be("/orgs/1/something"); - url2.AbsolutePath.Should().Be("/orgs/2/something"); + var url2 = client.BuildUriString(request); + + url1.Should().Be($"{host}/orgs/1/something"); + url2.Should().Be($"{host}/orgs/2/something"); } } \ No newline at end of file diff --git a/test/RestSharp.Tests/RestRequestTests.cs b/test/RestSharp.Tests/RestRequestTests.cs index 988f91734..dc2053c09 100644 --- a/test/RestSharp.Tests/RestRequestTests.cs +++ b/test/RestSharp.Tests/RestRequestTests.cs @@ -26,8 +26,8 @@ public void RestRequest_Test_Already_Encoded() { parameters.Should().BeEquivalentTo(expected, options => options.ExcludingMissingMembers()); using var client = new RestClient(baseUrl); - var actual = client.BuildUri(request); - actual.AbsoluteUri.Should().Be($"{baseUrl}{resource}"); + var actual = client.BuildUriString(request); + actual.Should().Be($"{baseUrl}{resource}"); } [Fact]