-Fixed double parsing bug
This commit is contained in:
@@ -53,8 +53,8 @@ namespace Newtonsoft.Json.Tests.Utilities
|
|||||||
bool result2 = double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out d2)
|
bool result2 = double.TryParse(s, NumberStyles.Float, CultureInfo.InvariantCulture, out d2)
|
||||||
&& !s.StartsWith(".")
|
&& !s.StartsWith(".")
|
||||||
&& !s.EndsWith(".")
|
&& !s.EndsWith(".")
|
||||||
&& !(s.StartsWith("0") && s.Length > 1 && !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("-0") && s.Length > 2 && !s.StartsWith("-0.") && !s.StartsWith("-0e", StringComparison.OrdinalIgnoreCase))
|
||||||
&& s.IndexOf(".e", StringComparison.OrdinalIgnoreCase) == -1;
|
&& s.IndexOf(".e", StringComparison.OrdinalIgnoreCase) == -1;
|
||||||
|
|
||||||
Assert.AreEqual(expectedResult, result);
|
Assert.AreEqual(expectedResult, result);
|
||||||
@@ -73,6 +73,8 @@ namespace Newtonsoft.Json.Tests.Utilities
|
|||||||
[Test]
|
[Test]
|
||||||
public void DoubleTryParse()
|
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("0.1", ParseResult.Success, 0.1);
|
||||||
AssertDoubleTryParse("567.89", ParseResult.Success, 567.89);
|
AssertDoubleTryParse("567.89", ParseResult.Success, 567.89);
|
||||||
|
|
||||||
|
|||||||
@@ -1318,17 +1318,17 @@ namespace Newtonsoft.Json.Utilities
|
|||||||
i++;
|
i++;
|
||||||
if (i != end)
|
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;
|
return ParseResult.Invalid;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user