-Added additional validation when parsing numbers

This commit is contained in:
James Newton-King
2014-06-29 22:16:45 +12:00
parent 72874ec3a3
commit 2960a7090e
4 changed files with 28 additions and 16 deletions
+19 -7
View File
@@ -631,19 +631,18 @@ namespace Newtonsoft.Json
while (true)
{
switch (_chars[charPos++])
switch (_chars[charPos])
{
case '\0':
if (_charsUsed == charPos - 1)
_charPos = charPos;
if (_charsUsed == charPos)
{
charPos--;
_charPos = charPos;
if (ReadData(true) == 0)
return;
}
else
{
_charPos = charPos - 1;
return;
}
break;
@@ -674,10 +673,23 @@ namespace Newtonsoft.Json
case '7':
case '8':
case '9':
charPos++;
break;
default:
_charPos = charPos - 1;
return;
_charPos = charPos;
char currentChar = _chars[_charPos];
if (char.IsWhiteSpace(currentChar)
|| currentChar == ','
|| currentChar == '}'
|| currentChar == ']'
|| currentChar == ')'
|| currentChar == '/')
{
return;
}
throw JsonReaderException.Create(this, "Unexpected character encountered while parsing number: {0}.".FormatWith(CultureInfo.InvariantCulture, currentChar));
}
}
}