Skip to content

Commit

Permalink
#603 trim final url
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Apr 27, 2021
1 parent 05d0a31 commit e24ff98
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Test/Flurl.Test/UrlBuilder/UrlBuildingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,5 +604,11 @@ public void can_append_trailing_slash() {
url.AppendPathSegment("///");
Assert.AreEqual("https://www.site.com/a/b/c///", url.ToString());
}

[Test]
public void url_trims_leading_and_trailing_whitespace() {
var url = new Url(" https://www.site.com \t");
Assert.AreEqual("https://www.site.com", url.ToString());
}
}
}
7 changes: 3 additions & 4 deletions src/Flurl/Url.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,9 @@ public string Fragment {
/// <summary>
/// Constructs a Url object from a string.
/// </summary>
/// <param name="baseUrl">The URL to use as a starting point (required)</param>
/// <exception cref="ArgumentNullException"><paramref name="baseUrl"/> is <see langword="null" />.</exception>
/// <param name="baseUrl">The URL to use as a starting point.</param>
public Url(string baseUrl = null) {
_originalString = baseUrl;
_originalString = baseUrl?.Trim();
}

/// <summary>
Expand Down Expand Up @@ -508,7 +507,7 @@ public string ToString(bool encodeSpaceAsPlus) {
QueryParams.Any() ? "?" : "",
QueryParams.ToString(encodeSpaceAsPlus),
Fragment?.Length > 0 ? "#" : "",
Fragment);
Fragment).Trim();
}

/// <summary>
Expand Down

0 comments on commit e24ff98

Please sign in to comment.