[git commit] sort: fix -k2M (wasn't skipping leading whitespace)

Denys Vlasenko vda.linux at googlemail.com
Fri Jul 29 14:05:50 UTC 2022


commit: https://git.busybox.net/busybox/commit/?id=00f2a35b835c6f49617f5379073e9063e7e683ce
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
compare_keys                                         848     862     +14

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 coreutils/sort.c     |  4 ++--
 testsuite/sort.tests | 11 +++++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/coreutils/sort.c b/coreutils/sort.c
index 9aac656fe..80b578fc2 100644
--- a/coreutils/sort.c
+++ b/coreutils/sort.c
@@ -357,9 +357,9 @@ static int compare_keys(const void *xarg, const void *yarg)
 			int dx;
 			char *xx, *yy;
 
-			xx = strptime(x, "%b", &thyme);
+			xx = strptime(skip_whitespace(x), "%b", &thyme);
 			dx = thyme.tm_mon;
-			yy = strptime(y, "%b", &thyme);
+			yy = strptime(skip_whitespace(y), "%b", &thyme);
 			if (!xx)
 				retval = (!yy) ? 0 : -1;
 			else if (!yy)
diff --git a/testsuite/sort.tests b/testsuite/sort.tests
index ff33e21b4..fb2cc91bd 100755
--- a/testsuite/sort.tests
+++ b/testsuite/sort.tests
@@ -219,4 +219,15 @@ testing "sort -h" \
 
 # testing "description" "command(s)" "result" "infile" "stdin"
 
+testing "sort -k2,2M" \
+"sort -k2,2M input" "\
+3 March
+2 April
+1  May
+" "\
+2 April
+1  May
+3 March
+" ""
+
 exit $FAILCOUNT


More information about the busybox-cvs mailing list