mirror of
https://gitee.com/zyjblog/oatpp.git
synced 2024-12-22 22:16:37 +08:00
Merge pull request #533 from langchr86/fix/negativ_number_parsing_in_any
fix negativ number parsing in oatpp::Any
This commit is contained in:
commit
4b8d6a40a5
@ -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();
|
||||
|
@ -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})");
|
||||
|
Loading…
Reference in New Issue
Block a user