mirror of https://mirror.osredm.com/root/redis.git
Revert "Improve GETRANGE command behavior (#12272)"
Although the commit #6ceadfb58 improves GETRANGE command behavior,
we can't accept it as we should avoid breaking changes for non-critical bug fixes.
This reverts commit 6ceadfb580
.
This commit is contained in:
parent
8afb72a326
commit
0aeb86d78d
|
@ -504,15 +504,24 @@ void getrangeCommand(client *c) {
|
|||
strlen = sdslen(str);
|
||||
}
|
||||
|
||||
if (start < 0) start += strlen;
|
||||
if (end < 0) end += strlen;
|
||||
if (strlen == 0 || start >= (long long)strlen || end < 0 || start > end) {
|
||||
/* Convert negative indexes */
|
||||
if (start < 0 && end < 0 && start > end) {
|
||||
addReply(c,shared.emptybulk);
|
||||
return;
|
||||
}
|
||||
if (start < 0) start = strlen+start;
|
||||
if (end < 0) end = strlen+end;
|
||||
if (start < 0) start = 0;
|
||||
if (end >= (long long)strlen) end = strlen-1;
|
||||
addReplyBulkCBuffer(c,(char*)str+start,end-start+1);
|
||||
if (end < 0) end = 0;
|
||||
if ((unsigned long long)end >= strlen) end = strlen-1;
|
||||
|
||||
/* Precondition: end >= 0 && end < strlen, so the only condition where
|
||||
* nothing can be returned is: start > end. */
|
||||
if (start > end || strlen == 0) {
|
||||
addReply(c,shared.emptybulk);
|
||||
} else {
|
||||
addReplyBulkCBuffer(c,(char*)str+start,end-start+1);
|
||||
}
|
||||
}
|
||||
|
||||
void mgetCommand(client *c) {
|
||||
|
|
|
@ -464,12 +464,6 @@ start_server {tags {"string"}} {
|
|||
assert_equal "" [r getrange mykey 5 3]
|
||||
assert_equal " World" [r getrange mykey 5 5000]
|
||||
assert_equal "Hello World" [r getrange mykey -5000 10000]
|
||||
assert_equal "" [r getrange mykey 0 -100]
|
||||
assert_equal "" [r getrange mykey 1 -100]
|
||||
assert_equal "" [r getrange mykey -1 -100]
|
||||
assert_equal "" [r getrange mykey -100 -99]
|
||||
assert_equal "" [r getrange mykey -100 -100]
|
||||
assert_equal "" [r getrange mykey -100 -101]
|
||||
}
|
||||
|
||||
test "GETRANGE against integer-encoded value" {
|
||||
|
@ -480,12 +474,6 @@ start_server {tags {"string"}} {
|
|||
assert_equal "" [r getrange mykey 5 3]
|
||||
assert_equal "4" [r getrange mykey 3 5000]
|
||||
assert_equal "1234" [r getrange mykey -5000 10000]
|
||||
assert_equal "" [r getrange mykey 0 -100]
|
||||
assert_equal "" [r getrange mykey 1 -100]
|
||||
assert_equal "" [r getrange mykey -1 -100]
|
||||
assert_equal "" [r getrange mykey -100 -99]
|
||||
assert_equal "" [r getrange mykey -100 -100]
|
||||
assert_equal "" [r getrange mykey -100 -101]
|
||||
}
|
||||
|
||||
test "GETRANGE fuzzing" {
|
||||
|
|
Loading…
Reference in New Issue