In JSONParser::parse_number(), only allow a single '-' at start

- also, don't allow multiple '.' decimal points. Add unit tests to
  cover these cases.
This commit is contained in:
Glen Fraser
2017-03-14 13:01:09 +01:00
parent 561c5bc981
commit 491b95099d
2 changed files with 26 additions and 4 deletions

View File

@@ -569,13 +569,15 @@ struct JSONParser {
bool isDouble = false;
bool isNegative = false;
long exp = 0;
if( offset < str.size() && str[offset] == '-' ) {
isNegative = true;
++offset;
}
for (; offset < str.size() ;) {
c = str[offset++];
if( c == '-' ) {
isNegative = true;
} else if( c >= '0' && c <= '9' ) {
if( c >= '0' && c <= '9' ) {
val += c;
} else if( c == '.' ) {
} else if( c == '.' && !isDouble ) {
val += c;
isDouble = true;
} else {