Skip to content

Commit

Permalink
Less restrict in-range check to allow more timespan formats that woul…
Browse files Browse the repository at this point in the history
…d be accepted by Utf8Parser.TryParse

Fix #100538
  • Loading branch information
danielmarbach committed May 11, 2024
1 parent 7ce5d0f commit b5f4d3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace System.Text.Json.Serialization.Converters
{
internal sealed class TimeSpanConverter : JsonPrimitiveConverter<TimeSpan>
{
private const int MinimumTimeSpanFormatLength = 8; // hh:mm:ss
private const int MinimumTimeSpanFormatLength = 1; // d
private const int MaximumTimeSpanFormatLength = 26; // -dddddddd.hh:mm:ss.fffffff
private const int MaximumEscapedTimeSpanFormatLength = JsonConstants.MaxExpansionFactorWhileEscaping * MaximumTimeSpanFormatLength;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,18 @@ private static void DeserializeLongJsonString(int stringLength)
}

[Theory]
[InlineData("1:00:00")]
[InlineData("1")]
[InlineData("10")]
[InlineData("00:01")]
[InlineData("0:00:02")]
[InlineData("0:00:00.0000001")]
[InlineData("0:00:00.0000010")]
[InlineData("0:00:00.0000100")]
[InlineData("0:00:00.0001000")]
[InlineData("0:00:00.0010000")]
[InlineData("0:00:00.0100000")]
[InlineData("0:00:00.1000000")]
[InlineData("23:59:59")]
[InlineData("\\u002D23:59:59", "-23:59:59")]
[InlineData("\\u0032\\u0033\\u003A\\u0035\\u0039\\u003A\\u0035\\u0039", "23:59:59")]
Expand Down Expand Up @@ -546,13 +558,13 @@ public static void TimeSpan_Read_KnownDifferences()
[InlineData("00:00:60")]
[InlineData("00:00:00.00000009")]
[InlineData("900000000.00:00:00")]
[InlineData("1:00:00")] // 'g' Format
[InlineData("1:2:00:00")] // 'g' Format
[InlineData("+00:00:00")]
[InlineData("2021-06-18")]
[InlineData("1$")]
[InlineData("10675199.02:48:05.4775808")] // TimeSpan.MaxValue + 1
[InlineData("-10675199.02:48:05.4775809")] // TimeSpan.MinValue - 1
[InlineData("")]
[InlineData("1234", false)]
[InlineData("{}", false)]
[InlineData("[]", false)]
Expand Down

0 comments on commit b5f4d3f

Please sign in to comment.