Skip to content

Commit 0921ecf

Browse files
committed
patch 7.4.1707
Problem: Cannot use empty dictionary key, even though it can be useful. Solution: Allow using an empty dictionary key.
1 parent e185c1e commit 0921ecf

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

src/eval.c

+5-11
Original file line numberDiff line numberDiff line change
@@ -2782,11 +2782,9 @@ get_lval(
27822782
if (len == -1)
27832783
{
27842784
/* "[key]": get key from "var1" */
2785-
key = get_tv_string(&var1); /* is number or string */
2786-
if (*key == NUL)
2785+
key = get_tv_string_chk(&var1); /* is number or string */
2786+
if (key == NULL)
27872787
{
2788-
if (!quiet)
2789-
EMSG(_(e_emptykey));
27902788
clear_tv(&var1);
27912789
return NULL;
27922790
}
@@ -5623,11 +5621,9 @@ eval_index(
56235621

56245622
if (len == -1)
56255623
{
5626-
key = get_tv_string(&var1);
5627-
if (*key == NUL)
5624+
key = get_tv_string_chk(&var1);
5625+
if (key == NULL)
56285626
{
5629-
if (verbose)
5630-
EMSG(_(e_emptykey));
56315627
clear_tv(&var1);
56325628
return FAIL;
56335629
}
@@ -7754,11 +7750,9 @@ get_dict_tv(char_u **arg, typval_T *rettv, int evaluate)
77547750
if (evaluate)
77557751
{
77567752
key = get_tv_string_buf_chk(&tvkey, buf);
7757-
if (key == NULL || *key == NUL)
7753+
if (key == NULL)
77587754
{
77597755
/* "key" is NULL when get_tv_string_buf_chk() gave an errmsg */
7760-
if (key != NULL)
7761-
EMSG(_(e_emptykey));
77627756
clear_tv(&tvkey);
77637757
goto failret;
77647758
}

src/hashtab.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ hash_hash(char_u *key)
468468
char_u *p;
469469

470470
if ((hash = *key) == 0)
471-
return (hash_T)0; /* Empty keys are not allowed, but we don't
472-
want to crash if we get one. */
471+
return (hash_T)0;
473472
p = key + 1;
474473

475474
/* A simplistic algorithm that appears to do very well.

src/testdir/test_expr.vim

+14
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,17 @@ func Test_version()
3636
call assert_false(has('patch-9.1.0'))
3737
call assert_false(has('patch-9.9.1'))
3838
endfunc
39+
40+
func Test_dict()
41+
let d = {'': 'empty', 'a': 'a', 0: 'zero'}
42+
call assert_equal('empty', d[''])
43+
call assert_equal('a', d['a'])
44+
call assert_equal('zero', d[0])
45+
call assert_true(has_key(d, ''))
46+
call assert_true(has_key(d, 'a'))
47+
48+
let d[''] = 'none'
49+
let d['a'] = 'aaa'
50+
call assert_equal('none', d[''])
51+
call assert_equal('aaa', d['a'])
52+
endfunc

src/version.c

+2
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,8 @@ static char *(features[]) =
748748

749749
static int included_patches[] =
750750
{ /* Add new patch number below this line */
751+
/**/
752+
1707,
751753
/**/
752754
1706,
753755
/**/

0 commit comments

Comments
 (0)