-
Notifications
You must be signed in to change notification settings - Fork 357
Description
Describe the bug
JsonReader
exhibits inconsistent behavior when processing incomplete JSON payloads.
Assemblies affected
- Microsoft.OData.Core 7.x
- Microsoft.OData.Core 8.x
- Microsoft.OData.Core 9.x
Steps to Reproduce
Consider the following test:
[Theory]
[InlineData("{\"NullProp\":null", false)] // No exception
[InlineData("{\"NullProp\":null ", false)] // No exception
[InlineData("{\"BooleanProp\":false", false)] // No exception
[InlineData("{\"BooleanProp\":false ", false)] // No exception
[InlineData("{\"NumberProp\":3.14", false)] // No exception
[InlineData("{\"NumberProp\":3.14", true)] // No exception
[InlineData("{\"NumberProp\":3.14 ", false)] // No exception
[InlineData("{\"NumberProp\":3.14x", false)] // No exception
[InlineData("{\"NumberProp\":3.14+", false)] // No exception
[InlineData("{\"ArrayProp\":{", false)] // No exception
[InlineData("{\"ArrayProp\":{ ", false)] // No exception
[InlineData("{\"ObjectProp\":{", false)] // No exception
[InlineData("{\"ObjectProp\":{ ", false)] // No exception
[InlineData("{\"NullProp\":nullx", false)] // Exception
[InlineData("{\"BooleanProp\":falsex", false)] // Exception
[InlineData("{\"StringProp\":\"foobar", false)] // Exception
[InlineData("{\"WhitespaceProp\": ", false)] // Exception
public void ReadPayload(string payload, bool isIeee754Compatible)
{
using (var reader = new JsonReader(new StringReader(payload), isIeee754Compatible))
{
reader.Read(); // {
reader.Read(); // Position reader at the beginning of the property
reader.GetValue();
reader.Read(); // Position reader at the beginning of the property value
reader.GetValue();
}
}
Expected behaviour
Consistent behavior - either an exception is thrown or not, depending on whether the input is valid. If the current behavior is by design, it should be clearly documented.
Actual behaviour
No exception is thrown for most of the test cases, except the last four. In cases where the payload ends with literals like null
, false
, or 3.14
(even with trailing characters like spaces, x
, or +
), the values are parsed successfully. For inputs like :{
, :{
, or :[
, reader.GetValue()
returns null
.
This is concerning because the caller may assume a valid object or array was returned, potentially leading to incorrect downstream behavior.
Additional details
The scenarios listed above may not be exhaustive. Additional edge cases should be tested to ensure consistent and predictable behavior across all input variations.