From a3fe2903bb0e66310a4c38a1aa264b068b35a90e Mon Sep 17 00:00:00 2001 From: Harmen Date: Wed, 13 Jan 2021 14:46:05 +0100 Subject: [PATCH] update lua depencency And deal with a more permissive `CheckString()` function: https://github.com/yuin/gopher-lua/commit/a519e4d1a4c3cf96f743c7eb4571f8f565d0df7d --- cmd_scripting_test.go | 8 ++++---- go.mod | 2 +- go.sum | 2 ++ integration/script_test.go | 12 ++++++------ lua.go | 14 ++++++++++++-- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/cmd_scripting_test.go b/cmd_scripting_test.go index 589b2ef0..1175f42a 100644 --- a/cmd_scripting_test.go +++ b/cmd_scripting_test.go @@ -432,22 +432,22 @@ func TestCmdEvalReply(t *testing.T) { mustContain(t, c, "EVAL", `return redis.error_reply()`, "0", - "string expected, got nil", + "wrong number or type of arguments", ) mustContain(t, c, "EVAL", `return redis.error_reply(1)`, "0", - "string expected, got number", + "wrong number or type of arguments", ) mustContain(t, c, "EVAL", `return redis.status_reply()`, "0", - "string expected, got nil", + "wrong number or type of arguments", ) mustContain(t, c, "EVAL", `return redis.status_reply(1)`, "0", - "string expected, got number", + "wrong number or type of arguments", ) } diff --git a/go.mod b/go.mod index b6f777e8..ff70f552 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/alicebob/miniredis/v2 require ( github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a - github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb + github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da ) go 1.13 diff --git a/go.sum b/go.sum index d7dd4967..378d5b0f 100644 --- a/go.sum +++ b/go.sum @@ -5,4 +5,6 @@ github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5P github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0= github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ= +github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da h1:NimzV1aGyq29m5ukMK0AMWEhFaL/lrEOaephfuoiARg= +github.com/yuin/gopher-lua v0.0.0-20200816102855-ee81675732da/go.mod h1:E1AXubJBdNmFERAOucpDIxNzeGfLzg0mYh+UfMWdChA= golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/integration/script_test.go b/integration/script_test.go index 5199507e..4f110a78 100644 --- a/integration/script_test.go +++ b/integration/script_test.go @@ -119,12 +119,12 @@ func TestLua(t *testing.T) { c.Do("EVAL", "return {ok = 'great', notok = 'yes'}", "0") // doc error? c.Do("EVAL", "return {1, 2, ok = 'great', notok = 'yes'}", "0") // doc error? - c.DoLoosely("EVAL", "return redis.error_reply(1)", "0") - c.DoLoosely("EVAL", "return redis.error_reply()", "0") - c.DoLoosely("EVAL", "return redis.error_reply(redis.error_reply('foo'))", "0") - c.DoLoosely("EVAL", "return redis.status_reply(1)", "0") - c.DoLoosely("EVAL", "return redis.status_reply()", "0") - c.DoLoosely("EVAL", "return redis.status_reply(redis.status_reply('foo'))", "0") + c.Error("type of arguments", "EVAL", "return redis.error_reply(1)", "0") + c.Error("type of arguments", "EVAL", "return redis.error_reply()", "0") + c.Error("type of arguments", "EVAL", "return redis.error_reply(redis.error_reply('foo'))", "0") + c.Error("type of arguments", "EVAL", "return redis.status_reply(1)", "0") + c.Error("type of arguments", "EVAL", "return redis.status_reply()", "0") + c.Error("type of arguments", "EVAL", "return redis.status_reply(redis.status_reply('foo'))", "0") }) // state inside lua diff --git a/lua.go b/lua.go index 2ad84378..2515a63e 100644 --- a/lua.go +++ b/lua.go @@ -95,14 +95,24 @@ func mkLuaFuncs(srv *server.Server, c *server.Peer) map[string]lua.LGFunction { "call": mkCall(true), "pcall": mkCall(false), "error_reply": func(l *lua.LState) int { - msg := l.CheckString(1) + v := l.Get(1) + msg, ok := v.(lua.LString) + if !ok { + l.Error(lua.LString("wrong number or type of arguments"), 1) + return 0 + } res := &lua.LTable{} res.RawSetString("err", lua.LString(msg)) l.Push(res) return 1 }, "status_reply": func(l *lua.LState) int { - msg := l.CheckString(1) + v := l.Get(1) + msg, ok := v.(lua.LString) + if !ok { + l.Error(lua.LString("wrong number or type of arguments"), 1) + return 0 + } res := &lua.LTable{} res.RawSetString("ok", lua.LString(msg)) l.Push(res)