]> granicus.if.org Git - vim/commitdiff
patch 7.4.1707 v7.4.1707
authorBram Moolenaar <Bram@vim.org>
Sun, 3 Apr 2016 20:44:36 +0000 (22:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 3 Apr 2016 20:44:36 +0000 (22:44 +0200)
Problem:    Cannot use empty dictionary key, even though it can be useful.
Solution:   Allow using an empty dictionary key.

src/eval.c
src/hashtab.c
src/testdir/test_expr.vim
src/version.c

index ab006b113c38ed6b652a07cc407f7b555beed890..070485f19e4e6e02034c9b20661c8e7c50a47675 100644 (file)
@@ -2782,11 +2782,9 @@ get_lval(
            if (len == -1)
            {
                /* "[key]": get key from "var1" */
-               key = get_tv_string(&var1);     /* is number or string */
-               if (*key == NUL)
+               key = get_tv_string_chk(&var1); /* is number or string */
+               if (key == NULL)
                {
-                   if (!quiet)
-                       EMSG(_(e_emptykey));
                    clear_tv(&var1);
                    return NULL;
                }
@@ -5623,11 +5621,9 @@ eval_index(
 
                    if (len == -1)
                    {
-                       key = get_tv_string(&var1);
-                       if (*key == NUL)
+                       key = get_tv_string_chk(&var1);
+                       if (key == NULL)
                        {
-                           if (verbose)
-                               EMSG(_(e_emptykey));
                            clear_tv(&var1);
                            return FAIL;
                        }
@@ -7754,11 +7750,9 @@ get_dict_tv(char_u **arg, typval_T *rettv, int evaluate)
        if (evaluate)
        {
            key = get_tv_string_buf_chk(&tvkey, buf);
-           if (key == NULL || *key == NUL)
+           if (key == NULL)
            {
                /* "key" is NULL when get_tv_string_buf_chk() gave an errmsg */
-               if (key != NULL)
-                   EMSG(_(e_emptykey));
                clear_tv(&tvkey);
                goto failret;
            }
index d1ba2c95286d81714631a39cfb7d9bfe529dfc5e..f9c7c2799498f8c4fda0aa42621962fcb228ea15 100644 (file)
@@ -468,8 +468,7 @@ hash_hash(char_u *key)
     char_u     *p;
 
     if ((hash = *key) == 0)
-       return (hash_T)0;       /* Empty keys are not allowed, but we don't
-                                  want to crash if we get one. */
+       return (hash_T)0;
     p = key + 1;
 
     /* A simplistic algorithm that appears to do very well.
index f5c9e26c0c216b1f5bea342faf90ffe3e1f4466f..33115c7f1fe223f10c25e43a0007df8af1123616 100644 (file)
@@ -36,3 +36,17 @@ func Test_version()
   call assert_false(has('patch-9.1.0'))
   call assert_false(has('patch-9.9.1'))
 endfunc
+
+func Test_dict()
+  let d = {'': 'empty', 'a': 'a', 0: 'zero'}
+  call assert_equal('empty', d[''])
+  call assert_equal('a', d['a'])
+  call assert_equal('zero', d[0])
+  call assert_true(has_key(d, ''))
+  call assert_true(has_key(d, 'a'))
+
+  let d[''] = 'none'
+  let d['a'] = 'aaa'
+  call assert_equal('none', d[''])
+  call assert_equal('aaa', d['a'])
+endfunc
index 4502f7fdf36d934fe9f27c5b3042d415c09b10e1..2f1e01b1a9eaeb3d0e89a13d32a2f1f53ce2d6f6 100644 (file)
@@ -748,6 +748,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1707,
 /**/
     1706,
 /**/