Skip to content

Commit f016ef4

Browse files
committed
Fixed StrCatExpression edge case and updated syntax.lua test accordingly to cover this bug.
1 parent 1fe1d67 commit f016ef4

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/prometheus/unparser.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -499,23 +499,23 @@ function Unparser:unparseExpression(expression, tabbing)
499499
return lhs .. self:optionalWhitespace() .. op .. self:optionalWhitespace() .. rhs;
500500
end
501501

502-
k = AstKind.StrCatExpression;
503-
if(expression.kind == k) then
504-
local lhs = self:unparseExpression(expression.lhs, tabbing);
505-
if(Ast.astKindExpressionToNumber(expression.lhs.kind) >= Ast.astKindExpressionToNumber(k)) then
506-
lhs = "(" .. lhs .. ")";
502+
k = AstKind.StrCatExpression
503+
if expression.kind == k then
504+
local lhs = self:unparseExpression(expression.lhs, tabbing)
505+
if Ast.astKindExpressionToNumber(expression.lhs.kind) >= Ast.astKindExpressionToNumber(k) then
506+
lhs = "(" .. lhs .. ")"
507507
end
508508

509-
local rhs = self:unparseExpression(expression.rhs, tabbing);
510-
if(Ast.astKindExpressionToNumber(expression.rhs.kind) >= Ast.astKindExpressionToNumber(k)) then
511-
rhs = "(" .. rhs .. ")";
509+
local rhs = self:unparseExpression(expression.rhs, tabbing)
510+
if Ast.astKindExpressionToNumber(expression.rhs.kind) >= Ast.astKindExpressionToNumber(k) then
511+
rhs = "(" .. rhs .. ")"
512512
end
513513

514-
if(self.numberCharsLookup[string.sub(lhs, #lhs, #lhs)]) then
515-
lhs = lhs .. " ";
514+
if self.numberCharsLookup[string.sub(lhs, #lhs, #lhs)] then
515+
lhs = lhs .. " "
516516
end
517517

518-
return lhs .. self:optionalWhitespace() .. ".." .. self:optionalWhitespace() .. rhs;
518+
return lhs .. self:optionalWhitespace() .. (tostring(rhs):sub(1, 1) == "." and ".. " or "..") .. self:optionalWhitespace() .. rhs
519519
end
520520

521521
local arithmeticOps = {

tests/syntax.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@ local pc, _ = pcall(function()
1111
return (0)[char]
1212
end)
1313

14-
print(pc == false and "yes" or "no")
14+
print(pc == false and "yes" or "no")
15+
local ok = pcall(function(...)
16+
print("hello " .. ...)
17+
end)
18+
print(ok and "no" or "yes")

0 commit comments

Comments
 (0)