fix: return an error when invalid number of arguments is passed. (#3584)

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2024-08-28 09:20:29 +03:00 committed by GitHub
parent 832b79563d
commit dc040b53ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 3 deletions

View file

@ -464,9 +464,12 @@ int RedisReplicateCommands(lua_State* lua) {
}
int RedisLogCommand(lua_State* lua) {
// if the arguments passed to redis.log are incorrect
// we still do not log the error. Therefore, even if
// for the no-op case we don't need to parse the arguments
int argc = lua_gettop(lua);
if (argc < 2) {
PushError(lua, "redis.log() requires two arguments or more.");
return RaiseError(lua);
}
return 0;
}

View file

@ -484,6 +484,8 @@ TEST_F(InterpreterTest, Log) {
EXPECT_EQ("nil", ser_.res);
EXPECT_TRUE(Execute(R"(redis.log(redis.LOG_WARNING, 'warn'))"));
EXPECT_EQ("nil", ser_.res);
EXPECT_FALSE(Execute(R"(redis.log(redis.LOG_WARNING))"));
EXPECT_THAT(error_, testing::HasSubstr("requires two arguments or more"));
}
TEST_F(InterpreterTest, Robust) {

View file

@ -57,6 +57,7 @@ def test_script_exists_redis6(r: redis.Redis):
@pytest.mark.parametrize("args", [("a",), tuple("abcdefghijklmn")])
@pytest.mark.unsupported_server_types("dragonfly")
def test_script_flush_errors_with_args(r, args):
with pytest.raises(redis.ResponseError):
raw_command(r, "SCRIPT FLUSH %s" % " ".join(args))