Skip to content
This repository has been archived by the owner on Dec 1, 2022. It is now read-only.

Commit

Permalink
Fix casting a string to a string. (#584)
Browse files Browse the repository at this point in the history
  • Loading branch information
CPWstatic committed Jul 12, 2021
1 parent fa5a8bd commit 8537a34
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/common/expression/TypeCastingExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ const Value& TypeCastingExpression::eval(ExpressionContext& ctx) {
break;
}
case Value::Type::STRING: {
result_.setStr(val.toString());
if (val.isStr()) {
result_.setStr(val.moveStr());
} else {
result_.setStr(val.toString());
}
break;
}
default: {
Expand Down
7 changes: 7 additions & 0 deletions src/common/expression/test/TypeCastingExpressionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ TEST_F(TypeCastingExpressionTest, TypeCastTest) {
EXPECT_EQ(eval.type(), Value::Type::STRING);
EXPECT_EQ(eval, "0.23");
}
{
auto typeCast = TypeCastingExpression::make(
&pool, Value::Type::STRING, ConstantExpression::make(&pool, "ABC"));
auto eval = Expression::eval(typeCast, gExpCtxt);
EXPECT_EQ(eval.type(), Value::Type::STRING);
EXPECT_EQ(eval, "ABC");
}
{
auto typeCast = TypeCastingExpression::make(
&pool, Value::Type::SET, ConstantExpression::make(&pool, 23));
Expand Down

0 comments on commit 8537a34

Please sign in to comment.