summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-02-29 22:05:26 +0100
committerBram Moolenaar <Bram@vim.org>2016-02-29 22:05:26 +0100
commit5131c144feb046c5e2b72e6c172159d80ce06b3c (patch)
treeb5b94c99c6137bdcdfed153263285be2bcefe228
parenta6b8976bb724f8c85dd5699d115d795f7b730298 (diff)
downloadvim-git-5131c144feb046c5e2b72e6c172159d80ce06b3c.tar.gz
patch 7.4.1464v7.4.1464
Problem: When the argument of sort() is zero or empty it fails. Solution: Make zero work as documented. (suggested by Yasuhiro Matsumoto)
-rw-r--r--src/eval.c14
-rw-r--r--src/testdir/test_sort.vim8
-rw-r--r--src/version.c2
3 files changed, 22 insertions, 2 deletions
diff --git a/src/eval.c b/src/eval.c
index a45b71de5..7d28e7137 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -19195,11 +19195,21 @@ do_sort_uniq(typval_T *argvars, typval_T *rettv, int sort)
goto theend; /* type error; errmsg already given */
if (i == 1)
info.item_compare_ic = TRUE;
- else
+ else if (argvars[1].v_type != VAR_NUMBER)
info.item_compare_func = get_tv_string(&argvars[1]);
+ else if (i != 0)
+ {
+ EMSG(_(e_invarg));
+ goto theend;
+ }
if (info.item_compare_func != NULL)
{
- if (STRCMP(info.item_compare_func, "n") == 0)
+ if (*info.item_compare_func == NUL)
+ {
+ /* empty string means default sort */
+ info.item_compare_func = NULL;
+ }
+ else if (STRCMP(info.item_compare_func, "n") == 0)
{
info.item_compare_func = NULL;
info.item_compare_numeric = TRUE;
diff --git a/src/testdir/test_sort.vim b/src/testdir/test_sort.vim
index 2b097ceb9..819514a97 100644
--- a/src/testdir/test_sort.vim
+++ b/src/testdir/test_sort.vim
@@ -35,3 +35,11 @@ func Test_sort_nested()
" test ability to call sort() from a compare function
call assert_equal([1, 3, 5], sort([3, 1, 5], 'Compare1'))
endfunc
+
+func Test_sort_default()
+ " docs say omitted, empty or zero argument sorts on string representation.
+ call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"]))
+ call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"], ''))
+ call assert_equal(["2", 1, 3.3], sort([3.3, 1, "2"], 0))
+ call assert_fails('call sort([3.3, 1, "2"], 3)', "E474")
+endfunc
diff --git a/src/version.c b/src/version.c
index f4ffb8fc6..24a27cc7c 100644
--- a/src/version.c
+++ b/src/version.c
@@ -744,6 +744,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1464,
+/**/
1463,
/**/
1462,