Detect IncompleteInput in false, true, and null

This commit is contained in:
Benoit Blanchon
2019-02-18 16:18:11 +01:00
parent 56bf24e1ec
commit 4181de119c
6 changed files with 86 additions and 13 deletions

View File

@ -253,18 +253,29 @@ class JsonDeserializer {
if (isInteger(buffer)) {
result.setInteger(parseInteger<Integer>(buffer));
} else if (isFloat(buffer)) {
result.setFloat(parseFloat<Float>(buffer));
} else if (!strcmp(buffer, "true")) {
result.setBoolean(true);
} else if (!strcmp(buffer, "false")) {
result.setBoolean(false);
} else if (!strcmp(buffer, "null")) {
// already null
} else {
return DeserializationError::InvalidInput;
return DeserializationError::Ok;
}
return DeserializationError::Ok;
if (isFloat(buffer)) {
result.setFloat(parseFloat<Float>(buffer));
return DeserializationError::Ok;
}
c = buffer[0];
if (c == 't') { // true
result.setBoolean(true);
return n == 4 ? DeserializationError::Ok
: DeserializationError::IncompleteInput;
}
if (c == 'f') { // false
result.setBoolean(false);
return n == 5 ? DeserializationError::Ok
: DeserializationError::IncompleteInput;
}
if (c == 'n') { // null
// the variant is already null
return n == 4 ? DeserializationError::Ok
: DeserializationError::IncompleteInput;
}
return DeserializationError::InvalidInput;
}
DeserializationError parseCodepoint(uint16_t &codepoint) {