diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonConstants.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonConstants.cs index a2e91cd3b08fc..9ccbdf41516d1 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonConstants.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonConstants.cs @@ -95,6 +95,8 @@ internal static class JsonConstants public const int MinimumDateTimeParseLength = 10; // YYYY-MM-DD public const int MaximumEscapedDateTimeOffsetParseLength = MaxExpansionFactorWhileEscaping * MaximumDateTimeOffsetParseLength; + public const int MaximumLiteralLength = 5; // Must be able to fit null, true, & false. + // Encoding Helpers public const char HighSurrogateStart = '\ud800'; public const char HighSurrogateEnd = '\udbff'; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs index a248e32735c7c..80d08d1f993bd 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/JsonHelpers.Escaping.cs @@ -38,7 +38,7 @@ public static byte[] GetEscapedPropertyNameSection(ReadOnlySpan utf8Value, int length = JsonWriterHelper.GetMaxEscapedLength(utf8Value.Length, firstEscapeIndexVal); Span escapedValue = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (valueArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8Value, escapedValue, firstEscapeIndexVal, encoder, out int written); @@ -66,7 +66,7 @@ public static byte[] GetEscapedPropertyNameSection(ReadOnlySpan utf8Value, int length = JsonWriterHelper.GetMaxEscapedLength(utf8Value.Length, firstEscapeIndexVal); Span escapedValue = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (valueArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8Value, escapedValue, firstEscapeIndexVal, encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.Unescaping.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.Unescaping.cs index 0d739225d3499..11c415f216958 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.Unescaping.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.Unescaping.cs @@ -15,7 +15,7 @@ public static bool TryGetUnescapedBase64Bytes(ReadOnlySpan utf8Source, int byte[]? unescapedArray = null; Span utf8Unescaped = utf8Source.Length <= JsonConstants.StackallocThreshold ? - stackalloc byte[utf8Source.Length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, utf8Source.Length) : (unescapedArray = ArrayPool.Shared.Rent(utf8Source.Length)); Unescape(utf8Source, utf8Unescaped, idx, out int written); @@ -45,7 +45,7 @@ public static string GetUnescapedString(ReadOnlySpan utf8Source, int idx) byte[]? pooledName = null; Span utf8Unescaped = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (pooledName = ArrayPool.Shared.Rent(length)); Unescape(utf8Source, utf8Unescaped, idx, out int written); @@ -72,7 +72,7 @@ public static ReadOnlySpan GetUnescapedSpan(ReadOnlySpan utf8Source, byte[]? pooledName = null; Span utf8Unescaped = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (pooledName = ArrayPool.Shared.Rent(length)); Unescape(utf8Source, utf8Unescaped, idx, out int written); @@ -97,7 +97,7 @@ public static bool UnescapeAndCompare(ReadOnlySpan utf8Source, ReadOnlySpa byte[]? unescapedArray = null; Span utf8Unescaped = utf8Source.Length <= JsonConstants.StackallocThreshold ? - stackalloc byte[utf8Source.Length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, utf8Source.Length) : (unescapedArray = ArrayPool.Shared.Rent(utf8Source.Length)); Unescape(utf8Source, utf8Unescaped, 0, out int written); @@ -128,11 +128,11 @@ public static bool UnescapeAndCompare(ReadOnlySequence utf8Source, ReadOnl int length = checked((int)utf8Source.Length); Span utf8Unescaped = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (unescapedArray = ArrayPool.Shared.Rent(length)); Span utf8Escaped = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (escapedArray = ArrayPool.Shared.Rent(length)); utf8Source.CopyTo(utf8Escaped); @@ -175,7 +175,7 @@ public static bool TryDecodeBase64(ReadOnlySpan utf8Unescaped, [NotNullWhe byte[]? pooledArray = null; Span byteSpan = utf8Unescaped.Length <= JsonConstants.StackallocThreshold ? - stackalloc byte[utf8Unescaped.Length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, utf8Unescaped.Length) : (pooledArray = ArrayPool.Shared.Rent(utf8Unescaped.Length)); OperationStatus status = Base64.DecodeFromUtf8(utf8Unescaped, byteSpan, out int bytesConsumed, out int bytesWritten); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs index 4ba1bff616b27..09a15447d0068 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/JsonReaderHelper.cs @@ -252,7 +252,7 @@ public static bool TryGetEscapedDateTime(ReadOnlySpan source, out DateTime Debug.Assert(backslash != -1); Debug.Assert(source.Length <= JsonConstants.MaximumEscapedDateTimeOffsetParseLength); - Span sourceUnescaped = stackalloc byte[source.Length]; + Span sourceUnescaped = (stackalloc byte[JsonConstants.MaximumEscapedDateTimeOffsetParseLength]).Slice(0, source.Length); Unescape(source, sourceUnescaped, backslash, out int written); Debug.Assert(written > 0); @@ -277,7 +277,7 @@ public static bool TryGetEscapedDateTimeOffset(ReadOnlySpan source, out Da Debug.Assert(backslash != -1); Debug.Assert(source.Length <= JsonConstants.MaximumEscapedDateTimeOffsetParseLength); - Span sourceUnescaped = stackalloc byte[source.Length]; + Span sourceUnescaped = (stackalloc byte[JsonConstants.MaximumEscapedDateTimeOffsetParseLength]).Slice(0, source.Length); Unescape(source, sourceUnescaped, backslash, out int written); Debug.Assert(written > 0); @@ -303,7 +303,7 @@ public static bool TryGetEscapedGuid(ReadOnlySpan source, out Guid value) int idx = source.IndexOf(JsonConstants.BackSlash); Debug.Assert(idx != -1); - Span utf8Unescaped = stackalloc byte[source.Length]; + Span utf8Unescaped = (stackalloc byte[JsonConstants.MaximumEscapedGuidLength]).Slice(0, source.Length); Unescape(source, utf8Unescaped, idx, out int written); Debug.Assert(written > 0); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs index e639610cc0b39..cbb0078917b86 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Reader/Utf8JsonReader.MultiSegment.cs @@ -540,9 +540,9 @@ private bool ConsumeLiteralMultiSegment(ReadOnlySpan literal, JsonTokenTyp private bool CheckLiteralMultiSegment(ReadOnlySpan span, ReadOnlySpan literal, out int consumed) { - Debug.Assert(span.Length > 0 && span[0] == literal[0]); + Debug.Assert(span.Length > 0 && span[0] == literal[0] && literal.Length <= JsonConstants.MaximumLiteralLength); - Span readSoFar = stackalloc byte[literal.Length]; + Span readSoFar = (stackalloc byte[JsonConstants.MaximumLiteralLength]).Slice(0, literal.Length); int written = 0; long prevTotalConsumed = _totalConsumed; diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs index 3767b7ff6d451..8ee3559f6afa1 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs @@ -54,7 +54,7 @@ public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, Jso int backslash = source.IndexOf(JsonConstants.BackSlash); Debug.Assert(backslash != -1); - Span sourceUnescaped = stackalloc byte[source.Length]; + Span sourceUnescaped = (stackalloc byte[MaximumEscapedTimeSpanFormatLength]).Slice(0, source.Length); JsonReaderHelper.Unescape(source, sourceUnescaped, backslash, out int written); Debug.Assert(written > 0); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs index 7852c0052001c..059496fef73a9 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Bytes.cs @@ -140,7 +140,7 @@ private void WriteBase64EscapeProperty(ReadOnlySpan propertyName, ReadOnly int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -163,7 +163,7 @@ private void WriteBase64EscapeProperty(ReadOnlySpan utf8PropertyName, Read int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs index fa96ffc6e8dc2..2dfe0143c501c 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTime.cs @@ -145,7 +145,7 @@ private void WriteStringEscapeProperty(ReadOnlySpan propertyName, DateTime int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -168,7 +168,7 @@ private void WriteStringEscapeProperty(ReadOnlySpan utf8PropertyName, Date int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs index 3cbfef7cf4fb5..cddbed5eb38c4 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.DateTimeOffset.cs @@ -144,7 +144,7 @@ private void WriteStringEscapeProperty(ReadOnlySpan propertyName, DateTime int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -167,7 +167,7 @@ private void WriteStringEscapeProperty(ReadOnlySpan utf8PropertyName, Date int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs index 861ce7e00599a..98466a4f2af11 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Decimal.cs @@ -144,7 +144,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan propertyName, decimal int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -167,7 +167,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, deci int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs index 359cfd4303676..09014dc828499 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Double.cs @@ -148,7 +148,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan propertyName, double v int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -171,7 +171,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, doub int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs index 6e46a4f6efbf8..acb67c00ffe00 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Float.cs @@ -148,7 +148,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan propertyName, float va int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -171,7 +171,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, floa int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.FormattedNumber.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.FormattedNumber.cs index e654b5270f16c..3bc2dc80d19a7 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.FormattedNumber.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.FormattedNumber.cs @@ -121,7 +121,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan propertyName, ReadOnly int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -144,7 +144,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, Read int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs index 899ff6febf347..4d08162e37813 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Guid.cs @@ -144,7 +144,7 @@ private void WriteStringEscapeProperty(ReadOnlySpan propertyName, Guid val int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -167,7 +167,7 @@ private void WriteStringEscapeProperty(ReadOnlySpan utf8PropertyName, Guid int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs index ed8e8107145c9..1b3df6a296e26 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.Literal.cs @@ -260,7 +260,7 @@ private void WriteLiteralEscapeProperty(ReadOnlySpan propertyName, ReadOnl int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -283,7 +283,7 @@ private void WriteLiteralEscapeProperty(ReadOnlySpan utf8PropertyName, Rea int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs index b231446cd6804..ce2c8862c0602 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.SignedNumber.cs @@ -214,7 +214,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan propertyName, long val int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -237,7 +237,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, long int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs index f838d3fa1936d..bfa780cd83e4b 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.String.cs @@ -122,7 +122,7 @@ private void WriteStringEscapeProperty(ReadOnlySpan propertyName, int firs // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - char* ptr = stackalloc char[length]; + char* ptr = stackalloc char[JsonConstants.StackallocThreshold]; escapedPropertyName = new Span(ptr, length); } } @@ -284,7 +284,7 @@ private void WriteStringEscapeProperty(ReadOnlySpan utf8PropertyName, int // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - byte* ptr = stackalloc byte[length]; + byte* ptr = stackalloc byte[JsonConstants.StackallocThreshold]; escapedPropertyName = new Span(ptr, length); } } @@ -897,7 +897,7 @@ private void WriteStringEscapeValueOnly(ReadOnlySpan escapedPropertyName, int length = JsonWriterHelper.GetMaxEscapedLength(utf8Value.Length, firstEscapeIndex); Span escapedValue = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (valueArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8Value, escapedValue, firstEscapeIndex, _options.Encoder, out int written); @@ -920,7 +920,7 @@ private void WriteStringEscapeValueOnly(ReadOnlySpan escapedPropertyName, int length = JsonWriterHelper.GetMaxEscapedLength(value.Length, firstEscapeIndex); Span escapedValue = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (valueArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(value, escapedValue, firstEscapeIndex, _options.Encoder, out int written); @@ -943,7 +943,7 @@ private void WriteStringEscapePropertyOnly(ReadOnlySpan propertyName, Read int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndex); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndex, _options.Encoder, out int written); @@ -966,7 +966,7 @@ private void WriteStringEscapePropertyOnly(ReadOnlySpan utf8PropertyName, int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndex); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndex, _options.Encoder, out int written); @@ -1078,7 +1078,7 @@ private void WriteStringEscapePropertyOrValue(ReadOnlySpan propertyName, R // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - char* ptr = stackalloc char[length]; + char* ptr = stackalloc char[JsonConstants.StackallocThreshold]; escapedValue = new Span(ptr, length); } } @@ -1102,7 +1102,7 @@ private void WriteStringEscapePropertyOrValue(ReadOnlySpan propertyName, R // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - char* ptr = stackalloc char[length]; + char* ptr = stackalloc char[JsonConstants.StackallocThreshold]; escapedPropertyName = new Span(ptr, length); } } @@ -1147,7 +1147,7 @@ private void WriteStringEscapePropertyOrValue(ReadOnlySpan utf8PropertyNam // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - byte* ptr = stackalloc byte[length]; + byte* ptr = stackalloc byte[JsonConstants.StackallocThreshold]; escapedValue = new Span(ptr, length); } } @@ -1171,7 +1171,7 @@ private void WriteStringEscapePropertyOrValue(ReadOnlySpan utf8PropertyNam // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - byte* ptr = stackalloc byte[length]; + byte* ptr = stackalloc byte[JsonConstants.StackallocThreshold]; escapedPropertyName = new Span(ptr, length); } } @@ -1216,7 +1216,7 @@ private void WriteStringEscapePropertyOrValue(ReadOnlySpan propertyName, R // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - byte* ptr = stackalloc byte[length]; + byte* ptr = stackalloc byte[JsonConstants.StackallocThreshold]; escapedValue = new Span(ptr, length); } } @@ -1240,7 +1240,7 @@ private void WriteStringEscapePropertyOrValue(ReadOnlySpan propertyName, R // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - char* ptr = stackalloc char[length]; + char* ptr = stackalloc char[JsonConstants.StackallocThreshold]; escapedPropertyName = new Span(ptr, length); } } @@ -1285,7 +1285,7 @@ private void WriteStringEscapePropertyOrValue(ReadOnlySpan utf8PropertyNam // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - char* ptr = stackalloc char[length]; + char* ptr = stackalloc char[JsonConstants.StackallocThreshold]; escapedValue = new Span(ptr, length); } } @@ -1309,7 +1309,7 @@ private void WriteStringEscapePropertyOrValue(ReadOnlySpan utf8PropertyNam // Cannot create a span directly since it gets assigned to parameter and passed down. unsafe { - byte* ptr = stackalloc byte[length]; + byte* ptr = stackalloc byte[JsonConstants.StackallocThreshold]; escapedPropertyName = new Span(ptr, length); } } diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs index 5b6698143f111..f00e9930f3733 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteProperties.UnsignedNumber.cs @@ -223,7 +223,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan propertyName, ulong va int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -246,7 +246,7 @@ private void WriteNumberEscapeProperty(ReadOnlySpan utf8PropertyName, ulon int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Helpers.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Helpers.cs index 6e617bdec880c..89f6f687cdeda 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Helpers.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.Helpers.cs @@ -40,7 +40,7 @@ private void Base64EncodeAndWrite(ReadOnlySpan bytes, Span output, i byte[]? outputText = null; Span encodedBytes = encodingLength <= JsonConstants.StackallocThreshold ? - stackalloc byte[encodingLength] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, encodingLength) : (outputText = ArrayPool.Shared.Rent(encodingLength)); OperationStatus status = Base64.EncodeToUtf8(bytes, encodedBytes, out int consumed, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs index 15cb0b8d1af5e..5da3f6e91850f 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.WriteValues.String.cs @@ -190,7 +190,7 @@ private void WriteStringEscapeValue(ReadOnlySpan value, int firstEscapeInd int length = JsonWriterHelper.GetMaxEscapedLength(value.Length, firstEscapeIndexVal); Span escapedValue = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (valueArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(value, escapedValue, firstEscapeIndexVal, _options.Encoder, out int written); @@ -337,7 +337,7 @@ private void WriteStringEscapeValue(ReadOnlySpan utf8Value, int firstEscap int length = JsonWriterHelper.GetMaxEscapedLength(utf8Value.Length, firstEscapeIndexVal); Span escapedValue = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (valueArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8Value, escapedValue, firstEscapeIndexVal, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs index 2c5cc11afbd7a..075976f02ee37 100644 --- a/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs +++ b/src/libraries/System.Text.Json/src/System/Text/Json/Writer/Utf8JsonWriter.cs @@ -663,7 +663,7 @@ private void WriteStartEscapeProperty(ReadOnlySpan utf8PropertyName, byte int length = JsonWriterHelper.GetMaxEscapedLength(utf8PropertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc byte[length] : + (stackalloc byte[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(utf8PropertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); @@ -806,7 +806,7 @@ private void WriteStartEscapeProperty(ReadOnlySpan propertyName, byte toke int length = JsonWriterHelper.GetMaxEscapedLength(propertyName.Length, firstEscapeIndexProp); Span escapedPropertyName = length <= JsonConstants.StackallocThreshold ? - stackalloc char[length] : + (stackalloc char[JsonConstants.StackallocThreshold]).Slice(0, length) : (propertyArray = ArrayPool.Shared.Rent(length)); JsonWriterHelper.EscapeString(propertyName, escapedPropertyName, firstEscapeIndexProp, _options.Encoder, out int written); diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDateTimeTestData.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDateTimeTestData.cs index 8d4efb5e3cb2a..8f4f2af3269c4 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDateTimeTestData.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/JsonDateTimeTestData.cs @@ -232,6 +232,11 @@ public static IEnumerable InvalidISO8601Tests() // High byte expansion - parsing fails early at 254 characters. yield return new object[] { "\"" + new string('\u20AC', 250) + "\"" }; yield return new object[] { "\"" + new string('\u20AC', 260) + "\"" }; + + // Whitespace + yield return new object[] { "\"\\t1997-07-16\"" }; + yield return new object[] { "\"1997-07-16 \"" }; + yield return new object[] { "\" 1997-07-16 \"" }; } public static IEnumerable DateTimeFractionTrimBaseTests() diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.ReadTests.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.ReadTests.cs index 75ad7d1e6bae4..3bfb3c9bbd6f2 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.ReadTests.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.ReadTests.cs @@ -467,6 +467,20 @@ public static void TimeSpan_Read_Success(string json, string? actual = null) Assert.Equal(value, JsonConvert.DeserializeObject($"\"{json}\"")); } + [Fact] + public static void TimeSpan_Read_Nullable_Tests() + { + TimeSpan? value = JsonSerializer.Deserialize("null"); + Assert.False(value.HasValue); + + value = JsonSerializer.Deserialize("\"23:59:59\""); + Assert.True(value.HasValue); + Assert.Equal(TimeSpan.Parse("23:59:59"), value); + Assert.Equal(value, JsonConvert.DeserializeObject("\"23:59:59\"")); + + Assert.Throws(() => JsonSerializer.Deserialize("null")); + } + [Fact] public static void TimeSpan_Read_KnownDifferences() { diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonReaderTests.TryGet.Date.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonReaderTests.TryGet.Date.cs index bd4cbdb864e77..e5bf98633c788 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonReaderTests.TryGet.Date.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonReaderTests.TryGet.Date.cs @@ -207,7 +207,7 @@ public static void TestingDateTimeMaxValue() [MemberData(nameof(JsonDateTimeTestData.InvalidISO8601Tests), MemberType = typeof(JsonDateTimeTestData))] public static void TryGetDateTime_HasValueSequence_False(string testString) { - static void test(string testString, bool isFinalBlock) + static void Test(string testString, bool isFinalBlock) { byte[] dataUtf8 = Encoding.UTF8.GetBytes(testString); ReadOnlySequence sequence = JsonTestHelper.GetSequence(dataUtf8, 1); @@ -224,15 +224,15 @@ static void test(string testString, bool isFinalBlock) JsonTestHelper.AssertThrows(json, (jsonReader) => jsonReader.GetDateTime()); } - test(testString, isFinalBlock: true); - test(testString, isFinalBlock: false); + Test(testString, isFinalBlock: true); + Test(testString, isFinalBlock: false); } [Theory] [MemberData(nameof(JsonDateTimeTestData.InvalidISO8601Tests), MemberType = typeof(JsonDateTimeTestData))] public static void TryGetDateTimeOffset_HasValueSequence_False(string testString) { - static void test(string testString, bool isFinalBlock) + static void Test(string testString, bool isFinalBlock) { byte[] dataUtf8 = Encoding.UTF8.GetBytes(testString); ReadOnlySequence sequence = JsonTestHelper.GetSequence(dataUtf8, 1); @@ -249,8 +249,8 @@ static void test(string testString, bool isFinalBlock) JsonTestHelper.AssertThrows(json, (jsonReader) => jsonReader.GetDateTimeOffset()); } - test(testString, isFinalBlock: true); - test(testString, isFinalBlock: false); + Test(testString, isFinalBlock: true); + Test(testString, isFinalBlock: false); } } } diff --git a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonReaderTests.TryGet.cs b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonReaderTests.TryGet.cs index 27a53606963c5..44b8d2bffb004 100644 --- a/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonReaderTests.TryGet.cs +++ b/src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Utf8JsonReaderTests.TryGet.cs @@ -1335,7 +1335,7 @@ public static void TestingStringsConversionToGuid(string testString, string expe [MemberData(nameof(JsonGuidTestData.ValidGuidTests), MemberType = typeof(JsonGuidTestData))] public static void TryGetGuid_HasValueSequence_RetrievesGuid(string testString, string expectedString) { - static void test(string testString, string expectedString, bool isFinalBlock) + static void Test(string testString, string expectedString, bool isFinalBlock) { byte[] dataUtf8 = Encoding.UTF8.GetBytes($"\"{testString}\""); ReadOnlySequence sequence = JsonTestHelper.GetSequence(dataUtf8, 1); @@ -1354,8 +1354,8 @@ static void test(string testString, string expectedString, bool isFinalBlock) Assert.Equal(expected, json.GetGuid()); } - test(testString, expectedString, isFinalBlock: true); - test(testString, expectedString, isFinalBlock: false); + Test(testString, expectedString, isFinalBlock: true); + Test(testString, expectedString, isFinalBlock: false); } [Theory] @@ -1378,7 +1378,7 @@ public static void TestingStringsInvalidConversionToGuid(string testString) [MemberData(nameof(JsonGuidTestData.InvalidGuidTests), MemberType = typeof(JsonGuidTestData))] public static void TryGetGuid_HasValueSequence_False(string testString) { - static void test(string testString, bool isFinalBlock) + static void Test(string testString, bool isFinalBlock) { byte[] dataUtf8 = Encoding.UTF8.GetBytes($"\"{testString}\""); ReadOnlySequence sequence = JsonTestHelper.GetSequence(dataUtf8, 1); @@ -1395,8 +1395,8 @@ static void test(string testString, bool isFinalBlock) JsonTestHelper.AssertThrows(json, (jsonReader) => jsonReader.GetGuid()); } - test(testString, isFinalBlock: true); - test(testString, isFinalBlock: false); + Test(testString, isFinalBlock: true); + Test(testString, isFinalBlock: false); } } }