Skip to content

Commit

Permalink
Fixing problem with invalid parse scientific form of numbers. (dotnet…
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximys authored and dakersnar committed Jul 28, 2022
1 parent d7c8bc1 commit 3de6672
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,6 @@ private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles
{
exp = exp * 10 + (ch - '0');
ch = ++p < strEnd ? *p : '\0';
if (exp > 1000)
{
exp = 9999;
while (char.IsAsciiDigit(ch))
{
ch = ++p < strEnd ? *p : '\0';
}
}
} while (char.IsAsciiDigit(ch));
if (negExp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,25 @@ public static void CustomFormatPerMille()
RunCustomFormatToStringTests(s_random, "#\u2030000000", CultureInfo.CurrentCulture.NumberFormat.NegativeSign, 6, PerMilleSymbolFormatter);
}

public static IEnumerable<object[]> RunFormatScientificNotationToBigIntegerAndViceVersaData()
{
yield return new object[] { "1E+1000", "1E+1000" };
yield return new object[] { "1E+1001", "1E+1001" };
}

[Theory]
[MemberData(nameof(RunFormatScientificNotationToBigIntegerAndViceVersaData))]
public static void RunFormatScientificNotationToBigIntegerAndViceVersa(string testingValue, string expectedResult)
{
BigInteger parsedValue;
string actualResult;

parsedValue = BigInteger.Parse(testingValue, NumberStyles.AllowExponent);
actualResult = parsedValue.ToString("E0");

Assert.Equal(expectedResult, actualResult);
}

private static void RunSimpleProviderToStringTests(Random random, string format, NumberFormatInfo provider, int precision, StringFormatter formatter)
{
string test;
Expand Down

0 comments on commit 3de6672

Please sign in to comment.