Skip to content

Commit

Permalink
disallowing xx and nx with ifeq
Browse files Browse the repository at this point in the history
Signed-off-by: Sarthak Aggarwal <[email protected]>
  • Loading branch information
sarthakaggarwal97 committed Dec 4, 2024
1 parent 66ad52d commit f18468f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/t_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ int parseExtendedStringArgumentsOrReply(client *c, int *flags, int *unit, robj *
/* clang-format off */
if ((opt[0] == 'n' || opt[0] == 'N') &&
(opt[1] == 'x' || opt[1] == 'X') && opt[2] == '\0' &&
!(*flags & OBJ_SET_XX) && (command_type == COMMAND_SET))
!(*flags & OBJ_SET_XX || *flags & OBJ_SET_IFEQ) && (command_type == COMMAND_SET))
{
*flags |= OBJ_SET_NX;
} else if ((opt[0] == 'x' || opt[0] == 'X') &&
(opt[1] == 'x' || opt[1] == 'X') && opt[2] == '\0' &&
!(*flags & OBJ_SET_NX) && (command_type == COMMAND_SET))
!(*flags & OBJ_SET_NX || *flags & OBJ_SET_IFEQ) && (command_type == COMMAND_SET))
{
*flags |= OBJ_SET_XX;
} else if ((opt[0] == 'g' || opt[0] == 'G') &&
Expand Down Expand Up @@ -321,7 +321,7 @@ int parseExtendedStringArgumentsOrReply(client *c, int *flags, int *unit, robj *
(opt[1] == 'f' || opt[1] == 'F') &&
(opt[2] == 'e' || opt[2] == 'E') &&
(opt[3] == 'q' || opt[3] == 'Q') && opt[4] == '\0' &&
next && (command_type == COMMAND_SET))
next && !(*flags & OBJ_SET_NX || *flags & OBJ_SET_XX) && (command_type == COMMAND_SET))
{
*flags |= OBJ_SET_IFEQ;
*compare_val = next;
Expand Down
16 changes: 2 additions & 14 deletions tests/unit/type/string.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -623,24 +623,12 @@ if {[string match {*jemalloc*} [s mem_allocator]]} {

test "SET with IFEQ conditional - with xx" {
r del foo

assert_equal {} [r set foo "new_value" ifeq "initial_value" xx]

r set foo "initial_value"

assert_equal {OK} [r set foo "new_value" ifeq "initial_value" xx]
assert_equal "new_value" [r get foo]
assert_error {ERR syntax error} {r set foo "new_value" ifeq "initial_value" xx}
}

test "SET with IFEQ conditional - with nx" {
r del foo

assert_equal {} [r set foo "new_value" ifeq "initial_value" nx]

r set foo "initial_value"

assert_equal {} [r set foo "new_value" ifeq "initial_value" nx]
assert_equal "initial_value" [r get foo]
assert_error {ERR syntax error} {r set foo "new_value" ifeq "initial_value" nx}
}

test {Extended SET EX option} {
Expand Down

0 comments on commit f18468f

Please sign in to comment.