Skip to content

Commit

Permalink
#568 don't add leading slash
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Nov 28, 2020
1 parent 9ce73ec commit 1185099
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions Test/Flurl.Test/UrlBuilder/UrlBuildingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,14 @@ public class UrlBuildingTests
return "http://www.mysite.com?y=2".SetQueryParams(new { x = 1, y = (string)null, z = "foo" }, nullValueHandling).ToString();
}

[Test]
public void can_append_path_segment() {
var url = "http://www.mysite.com".AppendPathSegment("endpoint");
Assert.AreEqual("http://www.mysite.com/endpoint", url.ToString());
[TestCase("http://www.mysite.com", "endpoint", "http://www.mysite.com/endpoint")]
[TestCase("path1", "path2", "path1/path2")] // #568
[TestCase("/path1/path2", "path3", "/path1/path2/path3")]
public void can_append_path_segment(string original, string segment, string result) {
Assert.AreEqual(result, original.AppendPathSegment(segment).ToString());
Assert.AreEqual(result, original.AppendPathSegment("/" + segment).ToString());
Assert.AreEqual(result, (original + "/").AppendPathSegment(segment).ToString());
Assert.AreEqual(result, (original + "/").AppendPathSegment("/" + segment).ToString());
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/Flurl/Url.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ public class Url
_trailingSlash = subpath.OrdinalEndsWith("/");
}

_leadingSlash = true;
_leadingSlash |= !IsRelative;
return this;
}

Expand Down

0 comments on commit 1185099

Please sign in to comment.