Skip to content

Commit

Permalink
#582 url-encoding bug with dates
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Dec 10, 2020
1 parent 1185099 commit edcf60a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Test/Flurl.Test/UrlBuilder/UrlBuildingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ public void encodes_query_params() {
Assert.AreEqual("http://www.mysite.com?x=%2450&y=2%2B2%3D4", url.ToString());
}

[Test] // #582
public void encodes_date_type_query_param() {
var date = new DateTime(2020, 12, 6, 10, 45, 1);
var url = "http://www.mysite.com".SetQueryParam("date", date);
Assert.AreEqual("http://www.mysite.com?date=2020-12-06T10%3A45%3A01.0000000", url.ToString());
}

[Test]
public void does_not_reencode_encoded_query_values() {
var url = "http://www.mysite.com".SetQueryParam("x", "%CD%EE%E2%FB%E9%20%E3%EE%E4", true);
Expand Down
2 changes: 1 addition & 1 deletion src/Flurl/QueryParamCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,6 @@ public string Encode(bool encodeSpaceAsPlus) =>
(Value == null) ? null :
(_encodedValue != null) ? _encodedValue :
(Value is string s) ? Url.Encode(s, encodeSpaceAsPlus) :
Value.ToInvariantString();
Url.Encode(Value.ToInvariantString(), encodeSpaceAsPlus);
}
}

0 comments on commit edcf60a

Please sign in to comment.