-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Scientific notation numbers with decimal separators support #39406
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -172,21 +172,38 @@ internal static void ValidateNumber(ReadOnlySpan<byte> utf8FormattedNumber) | |
| return; | ||
| } | ||
|
|
||
| // The non digit character inside the number | ||
| byte val = utf8FormattedNumber[i]; | ||
|
|
||
| if (val == '.') | ||
| { | ||
| i++; | ||
|
|
||
| while (i < utf8FormattedNumber.Length && JsonHelpers.IsDigit(utf8FormattedNumber[i])) | ||
| { | ||
| i++; | ||
| } | ||
|
|
||
| if (utf8FormattedNumber.Length < i) | ||
| { | ||
| throw new ArgumentException(SR.RequiredDigitNotFoundEndOfData, nameof(utf8FormattedNumber)); | ||
| } | ||
| } | ||
| else if (val == 'e' || val == 'E') | ||
|
|
||
| if (i == utf8FormattedNumber.Length) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| val = utf8FormattedNumber[i]; | ||
|
|
||
| if (val == 'e' || val == 'E') | ||
| { | ||
| i++; | ||
|
|
||
| if (i >= utf8FormattedNumber.Length) | ||
| if (utf8FormattedNumber.Length <= i) | ||
| { | ||
| throw new ArgumentException( | ||
| SR.RequiredDigitNotFoundEndOfData, | ||
| nameof(utf8FormattedNumber)); | ||
| throw new ArgumentException(SR.RequiredDigitNotFoundEndOfData, nameof(utf8FormattedNumber)); | ||
| } | ||
|
|
||
| val = utf8FormattedNumber[i]; | ||
|
|
@@ -203,11 +220,9 @@ internal static void ValidateNumber(ReadOnlySpan<byte> utf8FormattedNumber) | |
| nameof(utf8FormattedNumber)); | ||
| } | ||
|
|
||
| if (i >= utf8FormattedNumber.Length) | ||
| if (utf8FormattedNumber.Length <= i) | ||
| { | ||
| throw new ArgumentException( | ||
| SR.RequiredDigitNotFoundEndOfData, | ||
| nameof(utf8FormattedNumber)); | ||
| throw new ArgumentException(SR.RequiredDigitNotFoundEndOfData, nameof(utf8FormattedNumber)); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the tests hit every one of these throws?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently hitting the throws requires either a bug in this method (how we got here 😄) or a JsonElement having gotten into an invalid/corrupted state. (This method is here to guard against that corruption and to serve as validation for a future addition to the writer where it allows you to write the numeric string directly) Having written both this method and JsonElement, it's probably most efficient for me to write the tests to get the coverage on these throws... after we get this PR in so we get the broken success scenario fixed. |
||
| } | ||
|
|
||
| while (i < utf8FormattedNumber.Length && JsonHelpers.IsDigit(utf8FormattedNumber[i])) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.