]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
nl: fix --section-delimiter handling of single characters
authorKOBAYASHI Takashi <a1415tk@aiit.ac.jp>
Mon, 14 Dec 2020 16:17:10 +0000 (16:17 +0000)
committerPádraig Brady <P@draigBrady.com>
Tue, 15 Dec 2020 14:11:55 +0000 (14:11 +0000)
* src/nl.c (main): Enforce the POSIX specified
behavior of assuming ':' is specified after a single
character argument to -d.
* tests/misc/nl.sh: Add a test case.
* NEWS: Mention the bug fix.

NEWS
src/nl.c
tests/misc/nl.sh

diff --git a/NEWS b/NEWS
index d2cb9ae4867502c302dee63b3ef2b83ae48da3c7..dfc7bfa4147b2ed2f027de0877b7e7d79cdcf784 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   ls no longer crashes when printing the SELinux context for unstatable files.
   [bug introduced in coreutils-6.9.91]
 
+  nl now handles single character --section-delimiter arguments,
+  by assuming a second ':' character has been specified, as specified by POSIX.
+  [This bug was present in "the beginning".]
+
   rm no longer skips an extra file when the removal of an empty directory fails.
   [bug introduced by the rewrite to use fts in coreutils-8.0]
 
index 23219b6091d7c4b226f412e587bcb4f66a8fe922..d1f45b29c1030e519404a80cc4f1eef71a903dfb 100644 (file)
--- a/src/nl.c
+++ b/src/nl.c
@@ -556,7 +556,8 @@ main (int argc, char **argv)
             }
           break;
         case 'd':
-          if (strlen (optarg) == 2)  /* POSIX.  */
+          len = strlen (optarg);
+          if (len == 1 || len == 2)  /* POSIX.  */
             {
               char *p = section_del;
               while (*optarg)
index 0d57f3443e0a0f47186e2c9ad7ffb1a106aa6fed..b64ab8e11c3984cdd96b3684072fce283289efda 100755 (executable)
@@ -99,4 +99,15 @@ cat <<EOF > exp
 EOF
 compare exp out || fail=1
 
+# Ensure single char delimiters assume a following ':' character (as per POSIX)
+# coreutils <= v8.32 didn't match single char delimiters at all
+printf '%s\n' a x:x: c > in.txt || framework_failure_
+nl -d 'x' in.txt > out || fail=1
+cat <<EOF > exp
+     1 a
+
+     1 c
+EOF
+compare exp out || fail=1
+
 Exit $fail