Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/core/interpreter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/interpreter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/fakeredis/test/test_mixins/test_scripting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Loading