-Fixed double parsing bug

This commit is contained in:
James Newton-King
2016-09-11 17:06:53 +12:00
parent 304136a60e
commit ca3af212de
2 changed files with 10 additions and 8 deletions
@@ -53,8 +53,8 @@ namespace Newtonsoft.Json.Tests.Utilities
bool result2 = double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out d2)
&& !s.StartsWith(".")
&& !s.EndsWith(".")
&& !(s.StartsWith("0") && s.Length > 1 && !s.StartsWith("0."))
&& !(s.StartsWith("-0") && s.Length > 2 && !s.StartsWith("-0."))
&& !(s.StartsWith("0") && s.Length > 1 && !s.StartsWith("0.") && !s.StartsWith("0e", StringComparison.OrdinalIgnoreCase))
&& !(s.StartsWith("-0") && s.Length > 2 && !s.StartsWith("-0.") && !s.StartsWith("-0e", StringComparison.OrdinalIgnoreCase))
&& s.IndexOf(".e", StringComparison.OrdinalIgnoreCase) == -1;
Assert.AreEqual(expectedResult, result);
@@ -73,6 +73,8 @@ namespace Newtonsoft.Json.Tests.Utilities
[Test]
public void DoubleTryParse()
{
AssertDoubleTryParse("0e-10", ParseResult.Success, 0e-10);
AssertDoubleTryParse("0E-10", ParseResult.Success, 0e-10);
AssertDoubleTryParse("0.1", ParseResult.Success, 0.1);
AssertDoubleTryParse("567.89", ParseResult.Success, 567.89);
@@ -1318,17 +1318,17 @@ namespace Newtonsoft.Json.Utilities
i++;
if (i != end)
{
if (chars[i] != '.')
c = chars[i];
if (c == '.')
{
return ParseResult.Invalid;
goto case '.';
}
if (i + 1 == end)
if (c == 'e' || c == 'E')
{
return ParseResult.Invalid;
goto case 'E';
}
numDecimalStart = i + 1;
continue;
return ParseResult.Invalid;
}
}