mirror of https://github.com/Icinga/icinga2.git
Implicitly convert Number argument to string for operator +
fixes #7823
This commit is contained in:
parent
31605402ea
commit
c220a99f2d
|
@ -202,7 +202,9 @@ Value icinga::operator+(const String& lhs, const Value& rhs)
|
|||
|
||||
Value icinga::operator+(const Value& lhs, const Value& rhs)
|
||||
{
|
||||
if ((lhs.IsString() || lhs.IsEmpty()) && (rhs.IsString() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
if ((lhs.IsEmpty() || lhs.IsNumber()) && (rhs.IsEmpty() || rhs.IsNumber()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return static_cast<double>(lhs) + static_cast<double>(rhs);
|
||||
if ((lhs.IsString() || lhs.IsEmpty() || lhs.IsNumber()) && (rhs.IsString() || rhs.IsEmpty() || rhs.IsNumber()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return static_cast<String>(lhs) + static_cast<String>(rhs);
|
||||
else if ((lhs.IsNumber() || lhs.IsEmpty()) && (rhs.IsNumber() || rhs.IsEmpty()) && !(lhs.IsEmpty() && rhs.IsEmpty()))
|
||||
return static_cast<double>(lhs) + static_cast<double>(rhs);
|
||||
|
|
|
@ -183,6 +183,18 @@ BOOST_AUTO_TEST_CASE(simple)
|
|||
expr = ConfigCompiler::CompileText("<test>", "test");
|
||||
BOOST_CHECK_THROW(expr->Evaluate(frame), ConfigError);
|
||||
delete expr;
|
||||
|
||||
expr = ConfigCompiler::CompileText("<test>", "null + 3");
|
||||
BOOST_CHECK(expr->Evaluate(frame) == 3);
|
||||
delete expr;
|
||||
|
||||
expr = ConfigCompiler::CompileText("<test>", "3 + null");
|
||||
BOOST_CHECK(expr->Evaluate(frame) == 3);
|
||||
delete expr;
|
||||
|
||||
expr = ConfigCompiler::CompileText("<test>", "\"test\" + 3");
|
||||
BOOST_CHECK(expr->Evaluate(frame) == "test3");
|
||||
delete expr;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(advanced)
|
||||
|
|
Loading…
Reference in New Issue