CC: Tweaked

CC: Tweaked

59M Downloads

`)(` is accepted as valid input to the REPL

khankul opened this issue ยท 1 comments

commented

Minecraft Version

1.20.x

Version

1.105.0

Details

  1. Launch a Lua shell
  2. Input print)( and hit Enter

  3. 1

It also works with functions like exit and term.clear.
For comparison,
PUC 5.4.4: syntax error near ')'
LuaJIT 2.1.0-beta3: '=' expected near ')'

I thought it might be a Cobalt issue, so I wrote a simple test (the same print statement) for it, but it crashes with CompileException: '=' expected near ')' so it has to be CC related.

commented

This issue is caused by lua prompt logic itself and not Cobalt related.
This is lines that cause it:

local func, err = load(input, name, "t", tEnv)
local expr_func = load("return _echo(" .. input .. ");", name, "t", tEnv)
if not func then
if expr_func then
func = expr_func
offset = 13
force_print = 1
end
elseif expr_func then
func = expr_func
offset = 13
end

This is side effect of lua prompt trying to echo a value that user entered if they just enter for example a string without any execution. In this case loaded string becomes return _echo(print)(); which cause _echo just returns all its arguments becomes valid print() call.