From e5c8e5eaffae28099c8b83db4fef501a899d23a4 Mon Sep 17 00:00:00 2001 From: TorchedSammy <38820196+TorchedSammy@users.noreply.github.com> Date: Sat, 17 Sep 2022 21:00:28 -0400 Subject: [PATCH] fix!: pass non expanded input to builtin runners fixes an issue with expanded aliases being added to history with a recent commit (6th time now with this issue?) and makes behavior with other runners consistent this can technically be a breaking change to people overriding the sh runner function --- exec.go | 15 ++++++++------- runnermode.go | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/exec.go b/exec.go index 5aee94a..caf7d1b 100644 --- a/exec.go +++ b/exec.go @@ -96,23 +96,23 @@ func runInput(input string, priv bool) { if currentRunner.Type() == rt.StringType { switch currentRunner.AsString() { case "hybrid": - _, _, err = handleLua(cmdString) + _, _, err = handleLua(input) if err == nil { cmdFinish(0, input, priv) return } - input, exitCode, cont, err = handleSh(cmdString) + input, exitCode, cont, err = handleSh(input) case "hybridRev": _, _, _, err = handleSh(input) if err == nil { cmdFinish(0, input, priv) return } - input, exitCode, err = handleLua(cmdString) + input, exitCode, err = handleLua(input) case "lua": - input, exitCode, err = handleLua(cmdString) + input, exitCode, err = handleLua(input) case "sh": - input, exitCode, cont, err = handleSh(cmdString) + input, exitCode, cont, err = handleSh(input) } } else { // can only be a string or function so @@ -130,7 +130,7 @@ func runInput(input string, priv bool) { } if cont { - cmdString, err = reprompt(input) + input, err = reprompt(input) if err == nil { goto rerun } else if err == io.EOF { @@ -195,7 +195,8 @@ func runLuaRunner(runr rt.Value, userInput string) (input string, exitCode uint8 return } -func handleLua(cmdString string) (string, uint8, error) { +func handleLua(input string) (string, uint8, error) { + cmdString := aliases.Resolve(input) // First try to load input, essentially compiling to bytecode chunk, err := l.CompileAndLoadLuaChunk("", []byte(cmdString), rt.TableValue(l.GlobalEnv())) if err != nil && noexecute { diff --git a/runnermode.go b/runnermode.go index b8995cd..c26ed03 100644 --- a/runnermode.go +++ b/runnermode.go @@ -28,13 +28,13 @@ func shRunner(t *rt.Thread, c *rt.GoCont) (rt.Cont, error) { return nil, err } - input, exitCode, cont, err := execSh(cmd) + _, exitCode, cont, err := execSh(aliases.Resolve(cmd)) var luaErr rt.Value = rt.NilValue if err != nil { luaErr = rt.StringValue(err.Error()) } runnerRet := rt.NewTable() - runnerRet.Set(rt.StringValue("input"), rt.StringValue(input)) + runnerRet.Set(rt.StringValue("input"), rt.StringValue(cmd)) runnerRet.Set(rt.StringValue("exitCode"), rt.IntValue(int64(exitCode))) runnerRet.Set(rt.StringValue("continue"), rt.BoolValue(cont)) runnerRet.Set(rt.StringValue("err"), luaErr)