Skip to content

Commit

Permalink
#669 bug setting query params w/ nullable props
Browse files Browse the repository at this point in the history
  • Loading branch information
tmenier committed Jan 27, 2022
1 parent a26520c commit 83101bc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Test/Flurl.Test/UrlBuilder/UrlBuildingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ public void ignores_null_or_empty_query_params(string original) {
Assert.AreEqual(original, modified2);
}

[Test] // #669
public void can_set_query_params_using_objects_with_nullable_types() {
int? x = 1;
int? y = null;
var query = new { x, y };
var url = new Url("https://api.com");
url.SetQueryParams(query);
Assert.AreEqual("https://api.com?x=1", url.ToString());
}

[Test] // #632
public void can_set_query_params_to_enums_cast_to_ints() {
var enumValues = new[] { FileMode.Append, FileMode.Create };
Expand Down
4 changes: 4 additions & 0 deletions src/Flurl/Util/CommonExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ internal static object GetDeclaredTypeValue(object value, Type declaredType) {
if (value == null || value.GetType() == declaredType)
return value;

// without this we had https://github.com/tmenier/Flurl/issues/669
// related: https://stackoverflow.com/q/3531318/62600
declaredType = Nullable.GetUnderlyingType(declaredType) ?? declaredType;

// added to deal with https://github.com/tmenier/Flurl/issues/632
// thx @j2jensen!
if (value is IEnumerable col
Expand Down

0 comments on commit 83101bc

Please sign in to comment.