Skip to content

Commit 76d854d

Browse files
committed
Fixing problem with invalid parse scientific form of numbers. (dotnet#17296)
1 parent 9dc08dd commit 76d854d

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/libraries/Common/src/System/Globalization/FormatProvider.Number.cs

-8
Original file line numberDiff line numberDiff line change
@@ -517,14 +517,6 @@ private static unsafe bool ParseNumber(ref char* str, char* strEnd, NumberStyles
517517
{
518518
exp = exp * 10 + (ch - '0');
519519
ch = ++p < strEnd ? *p : '\0';
520-
if (exp > 1000)
521-
{
522-
exp = 9999;
523-
while (ch >= '0' && ch <= '9')
524-
{
525-
ch = ++p < strEnd ? *p : '\0';
526-
}
527-
}
528520
} while (ch >= '0' && ch <= '9');
529521
if (negExp)
530522
{

src/libraries/System.Runtime.Numerics/tests/BigInteger/BigIntegerToStringTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,25 @@ public static void CustomFormatPerMille()
439439
RunCustomFormatToStringTests(s_random, "#\u2030000000", CultureInfo.CurrentCulture.NumberFormat.NegativeSign, 6, PerMilleSymbolFormatter);
440440
}
441441

442+
public static IEnumerable<object[]> RunFormatScientificNotationToBigIntegerAndViceVersaData()
443+
{
444+
yield return new object[] { "1E+1000", "1E+1000" };
445+
yield return new object[] { "1E+1001", "1E+1001" };
446+
}
447+
448+
[Theory]
449+
[MemberData(nameof(RunFormatScientificNotationToBigIntegerAndViceVersaData))]
450+
public static void RunFormatScientificNotationToBigIntegerAndViceVersa(string testingValue, string expectedResult)
451+
{
452+
BigInteger parsedValue;
453+
string actualResult;
454+
455+
parsedValue = BigInteger.Parse(testingValue, NumberStyles.AllowExponent);
456+
actualResult = parsedValue.ToString("E0");
457+
458+
Assert.Equal(expectedResult, actualResult);
459+
}
460+
442461
private static void RunSimpleProviderToStringTests(Random random, string format, NumberFormatInfo provider, int precision, StringFormatter formatter)
443462
{
444463
string test;

0 commit comments

Comments
 (0)