Skip to content

Commit

Permalink
DiceDB#1193: Add type check for string compatibility in evalAPPEND fu…
Browse files Browse the repository at this point in the history
…nction (DiceDB#1237)
  • Loading branch information
shashi-sah2003 authored Nov 12, 2024
1 parent f13c682 commit 51ccd04
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions integration_tests/commands/http/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ func TestAPPEND(t *testing.T) {
{Command: "del", Body: map[string]interface{}{"key": "key"}},
},
},
{
name: "APPEND to key created using ZADD",
commands: []HTTPCommand{
{Command: "ZADD", Body: map[string]interface{}{"key": "myzset", "values": []string{"1", "one"}}},
{Command: "APPEND", Body: map[string]interface{}{"key": "myzset", "value": "two"}},
},
expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"},
cleanup: []HTTPCommand{
{Command: "del", Body: map[string]interface{}{"key": "myzset"}},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/commands/resp/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func TestAPPEND(t *testing.T) {
expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"},
cleanup: []string{"del key"},
},
{
name: "APPEND to key created using ZADD",
commands: []string{"ZADD key 1 one", "APPEND key two"},
expected: []interface{}{int64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"},
cleanup: []string{"del key"},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions integration_tests/commands/websocket/append_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ func TestAppend(t *testing.T) {
expected: []interface{}{float64(4)},
cleanupKey: "key1",
},
{
name: "APPEND to key created using ZADD",
commands: []string{"ZADD key 1 one", "APPEND key two"},
expected: []interface{}{float64(1), "WRONGTYPE Operation against a key holding the wrong kind of value"},
cleanupKey: "key",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions internal/eval/store_eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,12 @@ func evalAPPEND(args []string, store *dstore.Store) *EvalResponse {
}
}
// Key exists path
if _, ok := obj.Value.(*sortedset.Set); ok {
return &EvalResponse{
Result: nil,
Error: diceerrors.ErrWrongTypeOperation,
}
}
_, currentEnc := object.ExtractTypeEncoding(obj)

var currentValueStr string
Expand Down

0 comments on commit 51ccd04

Please sign in to comment.