]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort: fix --debug marking for -b -k1.x
authorPádraig Brady <P@draigBrady.com>
Sun, 13 Dec 2015 02:14:06 +0000 (02:14 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 14 Dec 2015 13:40:51 +0000 (13:40 +0000)
We were erroneously skipping blanks in the marked comparison
_after_ the key start offset was applied.
* src/sort.c (debug_keys): Don't skip starting blanks
if already handled by begfield().
* tests/misc/sort-debug-keys.sh: Add a test case.
* NEWS: Mention the bug fix.
Fixes http://bugs.gnu.org/22155

NEWS
src/sort.c
tests/misc/sort-debug-keys.sh

diff --git a/NEWS b/NEWS
index 5941e20c24eb4d53cc0b8c7e7a36c7f6dbb98e2f..2731298ea75a94b4f9a25425381f948fb88d5803 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   shred again uses defined patterns for all iteration counts.
   [bug introduced in coreutils-5.93]
 
+  sort --debug -b now correctly marks the matching extents for keys
+  that specify an offset for the first field.
+  [bug introduced with the --debug feature in coreutils-8.6]
+
 ** New commands
 
   base32 is added to complement the existing base64 command,
index cf29727de3990949f58c0c6b30e3464dda86761a..37b3b8b8ffadfb9fd24f45a27b09b6ce98abd4c9 100644 (file)
@@ -2274,7 +2274,8 @@ debug_key (struct line const *line, struct keyfield const *key)
       if (key->eword != SIZE_MAX)
         lim = limfield (line, key);
 
-      if (key->skipsblanks || key->month || key_numeric (key))
+      if ((key->skipsblanks && key->sword == SIZE_MAX)
+          || key->month || key_numeric (key))
         {
           char saved = *lim;
           *lim = '\0';
index a0a287401d8f8e038f828659c3a8d85ab8df3f5f..fadd19c6ac50df63a8439e200ba59cb791b88927 100755 (executable)
@@ -238,6 +238,10 @@ A>chr10
      ^ no match for key
 B>chr1
      ^ no match for key
+1 2
+ __
+1 3
+ __
 EOF
 
 (
@@ -282,6 +286,9 @@ printf '\0\ta\n' | sort -s -k2b,2 --debug | tr -d '\0'
 
 # Check that key end before key start is not underlined
 printf 'A\tchr10\nB\tchr1\n' | sort -s -k2.4b,2.3n --debug
+
+# Ensure that -b applied before -k offsets
+printf '1 2\n1 3\n' | sort -s -k1.2b --debug
 ) > out
 
 compare exp out || fail=1