49c94e6
diff -urNp coreutils-7.1-orig/src/sort.c coreutils-7.1/src/sort.c
49c94e6
--- coreutils-7.1-orig/src/sort.c	2009-02-25 16:15:52.000000000 +0100
49c94e6
+++ coreutils-7.1/src/sort.c	2009-02-25 16:20:35.000000000 +0100
49c94e6
@@ -1598,6 +1598,9 @@ limfield_uni (const struct line *line, c
49c94e6
   size_t eword = key->eword, echar = key->echar;
49c94e6
   size_t remaining_bytes;
49c94e6
 
49c94e6
+  if (echar == 0)
49c94e6
+    eword++; /* skip all of end field. */
49c94e6
+
49c94e6
   /* Move PTR past EWORD fields or to one past the last byte on LINE,
49c94e6
      whichever comes first.  If there are more than EWORD fields, leave
49c94e6
      PTR pointing at the beginning of the field having zero-based index,
49c94e6
@@ -1673,19 +1676,22 @@ limfield_uni (const struct line *line, c
49c94e6
     }
49c94e6
 #endif
49c94e6
 
49c94e6
-  /* If we're ignoring leading blanks when computing the End
49c94e6
-     of the field, don't start counting bytes until after skipping
49c94e6
-     past any leading blanks. */
49c94e6
-  if (key->skipeblanks)
49c94e6
-    while (ptr < lim && blanks[to_uchar (*ptr)])
49c94e6
-      ++ptr;
49c94e6
 
49c94e6
-  /* Advance PTR by ECHAR (if possible), but no further than LIM.  */
49c94e6
-  remaining_bytes = lim - ptr;
49c94e6
-  if (echar < remaining_bytes)
49c94e6
-    ptr += echar;
49c94e6
-  else
49c94e6
-    ptr = lim;
49c94e6
+  if (echar != 0) /* We need to skip over a portion of the end field.  */
49c94e6
+    {
49c94e6
+      if (key->skipeblanks) /* blanks not counted in echar.  */
49c94e6
+        {
49c94e6
+          while (ptr < lim && blanks[to_uchar (*ptr)])
49c94e6
+            ++ptr;
49c94e6
+        }
49c94e6
+
49c94e6
+      /* Advance PTR by ECHAR (if possible), but no further than LIM.  */
49c94e6
+      remaining_bytes = lim - ptr;
49c94e6
+      if (echar < remaining_bytes)
49c94e6
+        ptr += echar;
49c94e6
+      else
49c94e6
+        ptr = lim;
49c94e6
+    }
49c94e6
 
49c94e6
   return ptr;
49c94e6
 }
49c94e6
@@ -3736,12 +3742,9 @@ main (int argc, char **argv)
49c94e6
 		  badfieldspec (optarg, N_("field number is zero"));
49c94e6
 		}
49c94e6
 	      if (*s == '.')
49c94e6
-		s = parse_field_count (s + 1, &key->echar,
49c94e6
-				       N_("invalid number after `.'"));
49c94e6
-	      else
49c94e6
 		{
49c94e6
-		  /* `-k 2,3' is equivalent to `+1 -3'.  */
49c94e6
-		  key->eword++;
49c94e6
+                 s = parse_field_count (s + 1, &key->echar,
49c94e6
+                                        N_("invalid number after `.'"));
49c94e6
 		}
49c94e6
 	      s = set_ordering (s, key, bl_end);
49c94e6
 	    }
49c94e6
diff -urNp coreutils-7.1-orig/tests/misc/sort coreutils-7.1/tests/misc/sort
49c94e6
--- coreutils-7.1-orig/tests/misc/sort	2009-01-27 22:11:25.000000000 +0100
49c94e6
+++ coreutils-7.1/tests/misc/sort	2009-02-25 16:21:48.000000000 +0100
bfff213
@@ -24,6 +24,10 @@ my $prog = 'sort';
d540fa5
 # Turn off localization of executable's output.
bfff213
 @ENV{qw(LANGUAGE LANG LC_ALL)} = ('C') x 3;
bfff213
 
bfff213
+my $mb_locale = $ENV{LOCALE_FR_UTF8};
bfff213
+! defined $mb_locale || $mb_locale eq 'none'
bfff213
+ and $mb_locale = 'C';
bfff213
+
bfff213
 # Since each test is run with a file name and with redirected stdin,
bfff213
 # the name in the diagnostic is either the file name or "-".
bfff213
 # Normalize each diagnostic to use '-'.
bfff213
@@ -110,6 +114,8 @@ my @Tests =
49c94e6
 ["07b", '-k 2,3', {IN=>"a a b\nz a a\n"}, {OUT=>"z a a\na a b\n"}],
49c94e6
 ["07c", '-k 2,3', {IN=>"y k b\nz k a\n"}, {OUT=>"z k a\ny k b\n"}],
49c94e6
 ["07d", '+1 -3', {IN=>"y k b\nz k a\n"}, {OUT=>"z k a\ny k b\n"}],
49c94e6
+["07e", '-k 2,3.0', {IN=>"a a b\nz a a\n"}, {OUT=>"z a a\na a b\n"}],
49c94e6
+
49c94e6
 #
49c94e6
 # report an error for `.' without following char spec
49c94e6
 ["08a", '-k 2.,3', {EXIT=>2},
bfff213
@@ -210,6 +216,15 @@ my @Tests =
49c94e6
 # key start and key end.
49c94e6
 ["18e", '-nb -k1.1,1.2', {IN=>" 901\n100\n"}, {OUT=>"100\n 901\n"}],
49c94e6
 
49c94e6
+# When ignoring leading blanks for end position, ensure blanks from
49c94e6
+# next field are not included in the sort. I.E. order should not change here.
49c94e6
+["18f", '-k1,1b', {IN=>"a  y\na z\n"}, {OUT=>"a  y\na z\n"}],
49c94e6
+
bfff213
+# When ignoring leading blanks for start position, ensure blanks from
bfff213
+# next field are not included in the sort. I.E. order should not change here.
bfff213
+# This was noticed as an issue on fedora 8 (only in multibyte locales).
bfff213
+["18g", '-k1b,1', {IN=>"a y\na z\n"}, {OUT=>"a y\na z\n"},
bfff213
+ {ENV => "LC_ALL=$mb_locale"}],
49c94e6
 # This looks odd, but works properly -- 2nd keyspec is never
49c94e6
 # used because all lines are different.
49c94e6
 ["19a", '+0 +1nr', {IN=>"b 2\nb 1\nb 3\n"}, {OUT=>"b 1\nb 2\nb 3\n"}],