Skip to content

Commit

Permalink
Only implicitly convert strings to indexers
Browse files Browse the repository at this point in the history
refs #8074
  • Loading branch information
gunnarbeutner committed Dec 14, 2014
1 parent 1cb0231 commit b40e95d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/config/expression.cpp
Expand Up @@ -418,8 +418,9 @@ void icinga::BindToScope(Expression *& expr, ScopeSpecifier scopeSpec)
}

LiteralExpression *lexpr = dynamic_cast<LiteralExpression *>(expr);
ScriptFrame frame;

if (lexpr) {
if (lexpr && lexpr->Evaluate(frame).IsString()) {
Expression *scope = new GetScopeExpression(scopeSpec);
expr = new IndexerExpression(scope, lexpr, lexpr->GetDebugInfo());
}
Expand Down
10 changes: 10 additions & 0 deletions test/config-ops.cpp
Expand Up @@ -234,6 +234,7 @@ BOOST_AUTO_TEST_CASE(advanced)

expr = ConfigCompiler::CompileText("<test>", "a = 3 b = 3");
BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError);
delete expr;

expr = ConfigCompiler::CompileText("<test>", "function() { 3 }()");
BOOST_CHECK(expr->Evaluate(frame) == 3);
Expand Down Expand Up @@ -290,6 +291,15 @@ BOOST_AUTO_TEST_CASE(advanced)
expr = ConfigCompiler::CompileText("<test>", "7 & 15 > 6");
BOOST_CHECK(expr->Evaluate(frame));
delete expr;

expr = ConfigCompiler::CompileText("<test>", "\"a\" = 3");
BOOST_CHECK(expr->Evaluate(frame) == 3);
BOOST_CHECK(frame.Locals->Get("a") == 3);
delete expr;

expr = ConfigCompiler::CompileText("<test>", "3 = 3");
BOOST_CHECK_THROW(expr->Evaluate(frame), ScriptError);
delete expr;
}

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit b40e95d

Please sign in to comment.