Skip to content

Commit

Permalink
Assume whitespaces can be only on the start, or only at the end, add …
Browse files Browse the repository at this point in the history
…one more test case that should fail
  • Loading branch information
N0D4N committed Sep 21, 2021
1 parent 6dab515 commit 11efcbd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public override Version Read(ref Utf8JsonReader reader, Type typeToConvert, Json
}
#else
string? versionString = reader.GetString();
if (!string.IsNullOrEmpty(versionString) && !char.IsDigit(versionString[0]) && !char.IsDigit(versionString[versionString.Length - 1]))
if (!string.IsNullOrEmpty(versionString) && (!char.IsDigit(versionString[0]) || !char.IsDigit(versionString[versionString.Length - 1])))
{
throw ThrowHelper.GetFormatException(DataType.Version);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public static void Version_Read_Success(string json, string? actual = null)
[InlineData("1.-1")]
[InlineData(" 1.2.3.4")] //Valid but has leading whitespace
[InlineData("1.2.3.4 ")] //Valid but has trailing whitespace
[InlineData(" 1.2.3.4 ")] //Valid but has trailing and leading whitespaces
[InlineData("{}", false)]
[InlineData("[]", false)]
[InlineData("true", false)]
Expand Down

0 comments on commit 11efcbd

Please sign in to comment.