Comparison

util/prosodyctl/shell.lua @ 13483:7b070909bd15

prosodyctl shell: Fix invocation with 3+ command arguments The code correctly inserted the ',' when there was already a "%q" in the format string, but then the next argument would fail to match because it inserted ", %q" instead of "%q". The code now matches both, ensuring the generated code will not produce a syntax error with multiple arguments.
author Matthew Wild <mwild1@gmail.com>
date Wed, 24 Apr 2024 11:45:37 +0100
parent 13398:4ba11c2b915a
child 13590:d66f30855822
comparison
equal deleted inserted replaced
13482:4d697961546d 13483:7b070909bd15
81 if arg[2] then 81 if arg[2] then
82 local fmt = { "%s"; ":%s("; ")" }; 82 local fmt = { "%s"; ":%s("; ")" };
83 for i = 3, #arg do 83 for i = 3, #arg do
84 if arg[i]:sub(1, 1) == ":" then 84 if arg[i]:sub(1, 1) == ":" then
85 table.insert(fmt, i, ")%s("); 85 table.insert(fmt, i, ")%s(");
86 elseif i > 3 and fmt[i - 1] == "%q" then 86 elseif i > 3 and fmt[i - 1]:match("%%q$") then
87 table.insert(fmt, i, ", %q"); 87 table.insert(fmt, i, ", %q");
88 else 88 else
89 table.insert(fmt, i, "%q"); 89 table.insert(fmt, i, "%q");
90 end 90 end
91 end 91 end