diff --git a/RestSharp.Tests/UrlBuilderTests.cs b/RestSharp.Tests/UrlBuilderTests.cs index 8ccc62aa7..b4cb3d5d3 100644 --- a/RestSharp.Tests/UrlBuilderTests.cs +++ b/RestSharp.Tests/UrlBuilderTests.cs @@ -110,5 +110,29 @@ public void POST_with_resource_containing_tokens() Assert.Equal(expected, output); } + [Fact] + public void GET_with_empty_request() + { + var request = new RestRequest(); + var client = new RestClient("http://example.com/resource"); + + var expected = new Uri("http://example.com/resource"); + var output = client.BuildUri(request); + + Assert.Equal(expected, output); + } + + [Fact] + public void GET_with_empty_request_and_bare_hostname() + { + var request = new RestRequest(); + var client = new RestClient("http://example.com"); + + var expected = new Uri("http://example.com/"); + var output = client.BuildUri(request); + + Assert.Equal(expected, output); + } + } } diff --git a/RestSharp/RestClient.cs b/RestSharp/RestClient.cs index 991ad97a2..2a0e873dc 100644 --- a/RestSharp/RestClient.cs +++ b/RestSharp/RestClient.cs @@ -304,8 +304,17 @@ public Uri BuildUri(IRestRequest request) assembled = assembled.Substring(1); } - if(!string.IsNullOrEmpty(BaseUrl)) - assembled = string.Format("{0}/{1}", BaseUrl, assembled); + if (!string.IsNullOrEmpty(BaseUrl)) + { + if (string.IsNullOrEmpty(assembled)) + { + assembled = BaseUrl; + } + else + { + assembled = string.Format("{0}/{1}", BaseUrl, assembled); + } + } if (request.Method != Method.POST && request.Method != Method.PUT && request.Method != Method.PATCH) {