vim-patch:8.1.0802: negative index doesn't work for Blob

Problem:    Negative index doesn't work for Blob.
Solution:   Make it work, add a test. (closes vim/vim#3856)
a5be9b6248

Leave tv_blob_get()'s return type untouched.
This commit is contained in:
Sean Dewar
2021-07-29 22:54:47 +01:00
parent 23f5999d28
commit bd9c787b4f
3 changed files with 13 additions and 4 deletions

View File

@@ -4647,9 +4647,11 @@ eval_index(
tv_blob_set_ret(rettv, blob);
}
} else {
// The resulting variable is a string of a single
// character. If the index is too big or negative the
// result is empty.
// The resulting variable is a byte value.
// If the index is too big or negative that is an error.
if (n1 < 0) {
n1 = len + n1;
}
if (n1 < len && n1 >= 0) {
const int v = (int)tv_blob_get(rettv->vval.v_blob, n1);
tv_clear(rettv);