Merge pull request #533 from langchr86/fix/negativ_number_parsing_in_any

fix negativ number parsing in oatpp::Any
This commit is contained in:
Leonid Stryzhevskyi 2021-12-19 12:56:56 +02:00 committed by GitHub
commit 4b8d6a40a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View File

@ -480,12 +480,12 @@ std::string Utils::parseStringToStdString(ParsingCaret& caret){
bool Utils::findDecimalSeparatorInCurrentNumber(ParsingCaret& caret) {
parser::Caret::StateSaveGuard stateGuard(caret);
// search until a decimal separator is found or no more digits are found or no more data available
// search until a decimal separator is found or no more digits/sign are found or no more data available
while(caret.canContinue()) {
if (caret.isAtChar(JSON_DECIMAL_SEPARATOR)) {
return true;
}
if (!caret.isAtDigitChar()) {
if (!caret.isAtDigitChar() && !caret.isAtChar('-')) {
return false;
}
caret.inc();

View File

@ -197,13 +197,34 @@ void DeserializerTest::onRun(){
OATPP_ASSERT(dto->any.getStoredType() == Boolean::Class::getType());
OATPP_ASSERT(dto->any.retrieve<Boolean>() == false);
}
OATPP_LOGD(TAG, "Any: Float")
OATPP_LOGD(TAG, "Any: Negative Float")
{
auto dto = mapper->readFromString<oatpp::Object<AnyDto>>(R"({"any":-1.23456789,"another":1.1})");
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->any.getStoredType() == Float64::Class::getType());
OATPP_ASSERT(dto->any.retrieve<Float64>() == -1.23456789);
}
OATPP_LOGD(TAG, "Any: Positive Float")
{
auto dto = mapper->readFromString<oatpp::Object<AnyDto>>(R"({"any":1.23456789,"another":1.1})");
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->any.getStoredType() == Float64::Class::getType());
OATPP_ASSERT(dto->any.retrieve<Float64>() == 1.23456789);
}
OATPP_LOGD(TAG, "Any: Negative exponential Float")
{
auto dto = mapper->readFromString<oatpp::Object<AnyDto>>(R"({"any":-1.2345e30,"another":1.1})");
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->any.getStoredType() == Float64::Class::getType());
OATPP_ASSERT(dto->any.retrieve<Float64>() == -1.2345e30);
}
OATPP_LOGD(TAG, "Any: Positive exponential Float")
{
auto dto = mapper->readFromString<oatpp::Object<AnyDto>>(R"({"any":1.2345e30,"another":1.1})");
OATPP_ASSERT(dto);
OATPP_ASSERT(dto->any.getStoredType() == Float64::Class::getType());
OATPP_ASSERT(dto->any.retrieve<Float64>() == 1.2345e30);
}
OATPP_LOGD(TAG, "Any: Unsigned Integer")
{
auto dto = mapper->readFromString<oatpp::Object<AnyDto>>(R"({"any":12345678901234567890,"another":1.1})");