Fix bug found by Joey Hess and forwarded by Bastian Bunk. Add Joey Hess's
authorRob Landley <rob@landley.net>
Thu, 15 Jun 2006 20:50:38 +0000 (20:50 -0000)
committerRob Landley <rob@landley.net>
Thu, 15 Jun 2006 20:50:38 +0000 (20:50 -0000)
test case to the testsuite, plus another one that would have been broken by
the first attempt at a fix.

coreutils/sort.c
testsuite/sort.tests

index fb58f62790124a596aff0ff18cfad91c2321d868..3354385a4c5198023ed2b80e97d28bf0366ad725 100644 (file)
@@ -74,9 +74,7 @@ static char *get_key(char *str, struct sort_key *key, int flags)
                        for(i=1;i<key->range[2*j]+j;i++) {
                                /* Skip leading blanks or first separator */
                                if(str[end]) {
-                                       if(key_separator) {
-                                               if(str[end]==key_separator) end++;
-                                       } else if(isspace(str[end]))
+                                       if(!key_separator && isspace(str[end]))
                                                while(isspace(str[end])) end++;
                                }
                                /* Skip body of key */
index d1b42532da518d5fe90a23624014c6168616c34f..cd2e291b20393aac5c065dafe648ae2b216ab6c6 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 
 # SUSv3 compliant sort tests.
 # Copyright 2005 by Rob Landley <rob@landley.net>
@@ -66,4 +66,18 @@ testing "sort key range with multiple options" "sort -k2,3rn input" \
 egg    1       2       papyrus
 " "$data" ""
 
+testing "sort key doesn't strip leading blanks, disables fallback global sort" \
+"sort -n -k2 -t ' '" " a \n 1 \n 2 \n" "" " 2 \n 1 \n a \n" 
+
+testing "sort key edge case with -t" "sort -n -k4 -t/" \
+"/usr/lib/finish-install.d/1
+/usr/lib/finish-install.d/4
+/usr/lib/prebaseconfig.d/2
+/usr/lib/prebaseconfig.d/6
+" "" "/usr/lib/finish-install.d/1
+/usr/lib/prebaseconfig.d/2
+/usr/lib/finish-install.d/4
+/usr/lib/prebaseconfig.d/6
+"
+
 exit $FAILCOUNT