-
-
Notifications
You must be signed in to change notification settings - Fork 86
A null or whitespace string passed into Values<T1, T2*> causes HasValueX to return true #675
Copy link
Copy link
Closed
Labels
bugIssues describing a bug or pull requests fixing a bug.Issues describing a bug or pull requests fixing a bug.
Description
Describe the bug
When the Values(params object[] items) or Values(IEnumerable<object?> items) constructors are used, and:
- when the target
Tnis a string and the value is eithernullor a whitespace string; or - when the target
Tnis a nullable type; then
The constructor logic will evaluate HasValueX before assigning to ValueX, where ValueX returns an empty collection post-OneOrMany<Tn> cast.
Steps to reproduce
A simple reproducible sample can be achieved using https://schema.org/Reservation:
string json = """
{
"@context": "https://schema.org",
"@type": "Reservation",
"reservationId": "1",
"totalPrice": ""
}
""";
Schema.NET.Reservation reservation = Schema.NET.SchemaSerializer.DeserializeObject<Schema.NET.Reservation>(json)!;
_ = reservation.TotalPrice.Value3.Count == 0 ? "Correct, totalPrice should be an empty collection" : throw new InvalidDataException("totalPrice should be an empty collection");
_ = !reservation.TotalPrice.HasValue3 ? "Correct, totalPrice should not have any values" : throw new InvalidDataException("totalPrice should return false for HasValue3");- Deserialise simple
ReservationwheretotalPriceis an empty string. - Test that
Reservation.TotalPricehas no values for values property 3 (string). - Test that
Reservation.TotalPricereturnsfalseforHasValue3(optionally the same test forHasValue). - Observe that
InvalidDataExceptionis thrown with the messagetotalPrice should return false for HasValue3.
Expected behaviour
Reservation.TotalPrice.HasValue3 should return false, not true.
Schema objects
- All/any
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugIssues describing a bug or pull requests fixing a bug.Issues describing a bug or pull requests fixing a bug.