Skip to content

Commit 78c8cb9

Browse files
Less restrict in-range check to allow more timespan formats that would be accepted by Utf8Parser.TryParse (#102091)
Fix #100538 Co-authored-by: Daniel Marbach <[email protected]>
1 parent 741af4a commit 78c8cb9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/libraries/System.Text.Json/src/System/Text/Json/Serialization/Converters/Value/TimeSpanConverter.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace System.Text.Json.Serialization.Converters
88
{
99
internal sealed class TimeSpanConverter : JsonPrimitiveConverter<TimeSpan>
1010
{
11-
private const int MinimumTimeSpanFormatLength = 8; // hh:mm:ss
11+
private const int MinimumTimeSpanFormatLength = 1; // d
1212
private const int MaximumTimeSpanFormatLength = 26; // -dddddddd.hh:mm:ss.fffffff
1313
private const int MaximumEscapedTimeSpanFormatLength = JsonConstants.MaxExpansionFactorWhileEscaping * MaximumTimeSpanFormatLength;
1414

src/libraries/System.Text.Json/tests/System.Text.Json.Tests/Serialization/Value.ReadTests.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,18 @@ private static void DeserializeLongJsonString(int stringLength)
488488
}
489489

490490
[Theory]
491+
[InlineData("1:00:00")]
492+
[InlineData("1")]
493+
[InlineData("10")]
494+
[InlineData("00:01")]
495+
[InlineData("0:00:02")]
496+
[InlineData("0:00:00.0000001")]
497+
[InlineData("0:00:00.0000010")]
498+
[InlineData("0:00:00.0000100")]
499+
[InlineData("0:00:00.0001000")]
500+
[InlineData("0:00:00.0010000")]
501+
[InlineData("0:00:00.0100000")]
502+
[InlineData("0:00:00.1000000")]
491503
[InlineData("23:59:59")]
492504
[InlineData("\\u002D23:59:59", "-23:59:59")]
493505
[InlineData("\\u0032\\u0033\\u003A\\u0035\\u0039\\u003A\\u0035\\u0039", "23:59:59")]
@@ -546,13 +558,13 @@ public static void TimeSpan_Read_KnownDifferences()
546558
[InlineData("00:00:60")]
547559
[InlineData("00:00:00.00000009")]
548560
[InlineData("900000000.00:00:00")]
549-
[InlineData("1:00:00")] // 'g' Format
550561
[InlineData("1:2:00:00")] // 'g' Format
551562
[InlineData("+00:00:00")]
552563
[InlineData("2021-06-18")]
553564
[InlineData("1$")]
554565
[InlineData("10675199.02:48:05.4775808")] // TimeSpan.MaxValue + 1
555566
[InlineData("-10675199.02:48:05.4775809")] // TimeSpan.MinValue - 1
567+
[InlineData("")]
556568
[InlineData("1234", false)]
557569
[InlineData("{}", false)]
558570
[InlineData("[]", false)]

0 commit comments

Comments
 (0)