-Fixed number parsing culture bugs

This commit is contained in:
James Newton-King
2014-01-08 22:28:25 +13:00
parent 6562d9d31c
commit 62f6a2c256
4 changed files with 7 additions and 5 deletions
+1 -1
View File
@@ -178,7 +178,7 @@ namespace Newtonsoft.Json.Tests
{ {
try try
{ {
; action(); action();
Assert.Fail("Exception of type {0} expected; got none exception", typeof(TException).Name); Assert.Fail("Exception of type {0} expected; got none exception", typeof(TException).Name);
} }
+1 -1
View File
@@ -1289,7 +1289,7 @@ namespace Newtonsoft.Json
else else
{ {
double d; double d;
if (double.TryParse(number, NumberStyles.Float | NumberStyles.AllowThousands, NumberFormatInfo.CurrentInfo, out d)) if (double.TryParse(number, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out d))
numberValue = d; numberValue = d;
else else
throw JsonReaderException.Create(this, "Input string '{0}' is not a valid number.".FormatWith(CultureInfo.InvariantCulture, number)); throw JsonReaderException.Create(this, "Input string '{0}' is not a valid number.".FormatWith(CultureInfo.InvariantCulture, number));
+2 -2
View File
@@ -490,7 +490,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
if (numberText.IndexOfAny(new char[] { '.', 'E', 'e' }) != -1) if (numberText.IndexOfAny(new char[] { '.', 'E', 'e' }) != -1)
{ {
double d; double d;
if (double.TryParse(numberText, out d)) if (double.TryParse(numberText, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out d))
return d; return d;
else else
throw new JsonException("Could not read query value."); throw new JsonException("Could not read query value.");
@@ -498,7 +498,7 @@ namespace Newtonsoft.Json.Linq.JsonPath
else else
{ {
long l; long l;
if (long.TryParse(numberText, out l)) if (long.TryParse(numberText, NumberStyles.Integer, CultureInfo.InvariantCulture, out l))
return l; return l;
else else
throw new JsonException("Could not read query value."); throw new JsonException("Could not read query value.");
+3 -1
View File
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Newtonsoft.Json.ruleset" ToolsVersion="10.0"> <RuleSet Name="Newtonsoft.Json.ruleset" ToolsVersion="12.0">
<IncludeAll Action="Warning" /> <IncludeAll Action="Warning" />
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed"> <Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1000" Action="None" /> <Rule Id="CA1000" Action="None" />
@@ -67,6 +67,8 @@
<Rule Id="CA1301" Action="None" /> <Rule Id="CA1301" Action="None" />
<Rule Id="CA1302" Action="None" /> <Rule Id="CA1302" Action="None" />
<Rule Id="CA1303" Action="None" /> <Rule Id="CA1303" Action="None" />
<Rule Id="CA1304" Action="Error" />
<Rule Id="CA1305" Action="Error" />
<Rule Id="CA1306" Action="None" /> <Rule Id="CA1306" Action="None" />
<Rule Id="CA1307" Action="None" /> <Rule Id="CA1307" Action="None" />
<Rule Id="CA1308" Action="None" /> <Rule Id="CA1308" Action="None" />