[vim] 19/139: patch 7.4.1707 Problem: Cannot use empty dictionary key, even though it can be useful. Solution: Allow using an empty dictionary key.

James McCoy jamessan at debian.org
Fri May 6 03:59:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

jamessan pushed a commit to branch debian/sid
in repository vim.

commit 0921ecff1c5a74541bad6c073e8ade32247403d8
Author: Bram Moolenaar <Bram at vim.org>
Date:   Sun Apr 3 22:44:36 2016 +0200

    patch 7.4.1707
    Problem:    Cannot use empty dictionary key, even though it can be useful.
    Solution:   Allow using an empty dictionary key.
---
 src/eval.c                | 16 +++++-----------
 src/hashtab.c             |  3 +--
 src/testdir/test_expr.vim | 14 ++++++++++++++
 src/version.c             |  2 ++
 4 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/eval.c b/src/eval.c
index ab006b1..070485f 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -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;
 	    }
diff --git a/src/hashtab.c b/src/hashtab.c
index d1ba2c9..f9c7c27 100644
--- a/src/hashtab.c
+++ b/src/hashtab.c
@@ -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.
diff --git a/src/testdir/test_expr.vim b/src/testdir/test_expr.vim
index f5c9e26..33115c7 100644
--- a/src/testdir/test_expr.vim
+++ b/src/testdir/test_expr.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 4502f7f..2f1e01b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -749,6 +749,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1707,
+/**/
     1706,
 /**/
     1705,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-vim/vim.git



More information about the pkg-vim-maintainers mailing list