GETRANGE: return empty string with negative, inverted start/end.

This commit is contained in:
antirez 2016-06-15 12:48:58 +02:00
parent eb45e11496
commit 2d86995273
2 changed files with 6 additions and 2 deletions

View File

@ -773,12 +773,12 @@ void bitcountCommand(client *c) {
if (getLongFromObjectOrReply(c,c->argv[3],&end,NULL) != C_OK)
return;
/* Convert negative indexes */
if (start < 0) start = strlen+start;
if (end < 0) end = strlen+end;
if (start < 0 && end < 0 && start > end) {
addReply(c,shared.czero);
return;
}
if (start < 0) start = strlen+start;
if (end < 0) end = strlen+end;
if (start < 0) start = 0;
if (end < 0) end = 0;
if (end >= strlen) end = strlen-1;

View File

@ -263,6 +263,10 @@ void getrangeCommand(client *c) {
}
/* 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;