Karsten Hopp d54068
To: vim_dev@googlegroups.com
Karsten Hopp d54068
Subject: Patch 7.4.411
Karsten Hopp d54068
Fcc: outbox
Karsten Hopp d54068
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp d54068
Mime-Version: 1.0
Karsten Hopp d54068
Content-Type: text/plain; charset=UTF-8
Karsten Hopp d54068
Content-Transfer-Encoding: 8bit
Karsten Hopp d54068
------------
Karsten Hopp d54068
Karsten Hopp d54068
Patch 7.4.411
Karsten Hopp d54068
Problem:    "foo bar" sorts before "foo" with sort(). (John Little)
Karsten Hopp d54068
Solution:   Avoid putting quotes around strings before comparing them.
Karsten Hopp d54068
Files:	    src/eval.c
Karsten Hopp d54068
Karsten Hopp d54068
Karsten Hopp d54068
*** ../vim-7.4.410/src/eval.c	2014-08-06 14:52:05.043236174 +0200
Karsten Hopp d54068
--- src/eval.c	2014-08-22 13:08:52.423905619 +0200
Karsten Hopp d54068
***************
Karsten Hopp d54068
*** 17382,17397 ****
Karsten Hopp d54068
      const void	*s2;
Karsten Hopp d54068
  {
Karsten Hopp d54068
      sortItem_T  *si1, *si2;
Karsten Hopp d54068
      char_u	*p1, *p2;
Karsten Hopp d54068
!     char_u	*tofree1, *tofree2;
Karsten Hopp d54068
      int		res;
Karsten Hopp d54068
      char_u	numbuf1[NUMBUFLEN];
Karsten Hopp d54068
      char_u	numbuf2[NUMBUFLEN];
Karsten Hopp d54068
  
Karsten Hopp d54068
      si1 = (sortItem_T *)s1;
Karsten Hopp d54068
      si2 = (sortItem_T *)s2;
Karsten Hopp d54068
!     p1 = tv2string(&si1->item->li_tv, &tofree1, numbuf1, 0);
Karsten Hopp d54068
!     p2 = tv2string(&si2->item->li_tv, &tofree2, numbuf2, 0);
Karsten Hopp d54068
      if (p1 == NULL)
Karsten Hopp d54068
  	p1 = (char_u *)"";
Karsten Hopp d54068
      if (p2 == NULL)
Karsten Hopp d54068
--- 17382,17419 ----
Karsten Hopp d54068
      const void	*s2;
Karsten Hopp d54068
  {
Karsten Hopp d54068
      sortItem_T  *si1, *si2;
Karsten Hopp d54068
+     typval_T	*tv1, *tv2;
Karsten Hopp d54068
      char_u	*p1, *p2;
Karsten Hopp d54068
!     char_u	*tofree1 = NULL, *tofree2 = NULL;
Karsten Hopp d54068
      int		res;
Karsten Hopp d54068
      char_u	numbuf1[NUMBUFLEN];
Karsten Hopp d54068
      char_u	numbuf2[NUMBUFLEN];
Karsten Hopp d54068
  
Karsten Hopp d54068
      si1 = (sortItem_T *)s1;
Karsten Hopp d54068
      si2 = (sortItem_T *)s2;
Karsten Hopp d54068
!     tv1 = &si1->item->li_tv;
Karsten Hopp d54068
!     tv2 = &si2->item->li_tv;
Karsten Hopp d54068
!     /* tv2string() puts quotes around a string and allocates memory.  Don't do
Karsten Hopp d54068
!      * that for string variables. Use a single quote when comparing with a
Karsten Hopp d54068
!      * non-string to do what the docs promise. */
Karsten Hopp d54068
!     if (tv1->v_type == VAR_STRING)
Karsten Hopp d54068
!     {
Karsten Hopp d54068
! 	if (tv2->v_type != VAR_STRING || item_compare_numeric)
Karsten Hopp d54068
! 	    p1 = (char_u *)"'";
Karsten Hopp d54068
! 	else
Karsten Hopp d54068
! 	    p1 = tv1->vval.v_string;
Karsten Hopp d54068
!     }
Karsten Hopp d54068
!     else
Karsten Hopp d54068
! 	p1 = tv2string(tv1, &tofree1, numbuf1, 0);
Karsten Hopp d54068
!     if (tv2->v_type == VAR_STRING)
Karsten Hopp d54068
!     {
Karsten Hopp d54068
! 	if (tv1->v_type != VAR_STRING || item_compare_numeric)
Karsten Hopp d54068
! 	    p2 = (char_u *)"'";
Karsten Hopp d54068
! 	else
Karsten Hopp d54068
! 	    p2 = tv2->vval.v_string;
Karsten Hopp d54068
!     }
Karsten Hopp d54068
!     else
Karsten Hopp d54068
! 	p2 = tv2string(tv2, &tofree2, numbuf2, 0);
Karsten Hopp d54068
      if (p1 == NULL)
Karsten Hopp d54068
  	p1 = (char_u *)"";
Karsten Hopp d54068
      if (p2 == NULL)
Karsten Hopp d54068
***************
Karsten Hopp d54068
*** 17411,17418 ****
Karsten Hopp d54068
  	res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
Karsten Hopp d54068
      }
Karsten Hopp d54068
  
Karsten Hopp d54068
!     /* When the result would be zero, compare the pointers themselves.  Makes
Karsten Hopp d54068
!      * the sort stable. */
Karsten Hopp d54068
      if (res == 0 && !item_compare_keep_zero)
Karsten Hopp d54068
  	res = si1->idx > si2->idx ? 1 : -1;
Karsten Hopp d54068
  
Karsten Hopp d54068
--- 17433,17440 ----
Karsten Hopp d54068
  	res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
Karsten Hopp d54068
      }
Karsten Hopp d54068
  
Karsten Hopp d54068
!     /* When the result would be zero, compare the item indexes.  Makes the
Karsten Hopp d54068
!      * sort stable. */
Karsten Hopp d54068
      if (res == 0 && !item_compare_keep_zero)
Karsten Hopp d54068
  	res = si1->idx > si2->idx ? 1 : -1;
Karsten Hopp d54068
  
Karsten Hopp d54068
*** ../vim-7.4.410/src/version.c	2014-08-17 17:24:03.967017727 +0200
Karsten Hopp d54068
--- src/version.c	2014-08-22 12:51:35.011943243 +0200
Karsten Hopp d54068
***************
Karsten Hopp d54068
*** 743,744 ****
Karsten Hopp d54068
--- 743,746 ----
Karsten Hopp d54068
  {   /* Add new patch number below this line */
Karsten Hopp d54068
+ /**/
Karsten Hopp d54068
+     411,
Karsten Hopp d54068
  /**/
Karsten Hopp d54068
Karsten Hopp d54068
-- 
Karsten Hopp d54068
I started out with nothing, and I still have most of it.
Karsten Hopp d54068
                                -- Michael Davis -- "Tonight Show"
Karsten Hopp d54068
Karsten Hopp d54068
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp d54068
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp d54068
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp d54068
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///