From b8034e5581ef40cc043da35ed01280b166da81ca Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 17 Oct 2013 00:57:24 +0200 Subject: [PATCH] Ensure proper type checking/coercion of "${expr}" Now we only rewrite "${expr}" to expr if expr is a string literal. --- src/libexpr/parser.y | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index dab71546f..b4f72e599 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -203,7 +203,8 @@ static Expr * stripIndentation(SymbolTable & symbols, vector & es) es2->push_back(new ExprString(symbols.create(s2))); } - return es2->size() == 1 ? (*es2)[0] : new ExprConcatStrings(true, es2); + /* If this is a single string, then don't do a concatenation. */ + return es2->size() == 1 && dynamic_cast((*es2)[0]) ? (*es2)[0] : new ExprConcatStrings(true, es2); } @@ -359,7 +360,7 @@ expr_simple | '"' string_parts '"' { /* For efficiency, and to simplify parse trees a bit. */ if ($2->empty()) $$ = new ExprString(data->symbols.create("")); - else if ($2->size() == 1) $$ = $2->front(); + else if ($2->size() == 1 && dynamic_cast($2->front())) $$ = $2->front(); else $$ = new ExprConcatStrings(true, $2); } | IND_STRING_OPEN ind_string_parts IND_STRING_CLOSE {