]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
pr: fix alignment of input tabs to multiple columns
authorErik Auerswald <auerswal@unix-ag.uni-kl.de>
Mon, 15 Feb 2021 21:21:17 +0000 (21:21 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 15 Feb 2021 21:31:07 +0000 (21:31 +0000)
This regression was introduced in commit COREUTILS-6_8-58-g553d347d3

* src/pr.c (init_parameters): Process tabs for multiple columns.
* tests/pr/pr-tests.pl: Add test cases.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/46422

NEWS
src/pr.c
tests/pr/pr-tests.pl

diff --git a/NEWS b/NEWS
index 778be3e80c0f94963613749b07388ca93d4d36e4..79bb25e8604d2073cd9b575d613c03780d8e8149 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   by assuming a second ':' character has been specified, as specified by POSIX.
   [This bug was present in "the beginning".]
 
+  pr again adjusts tabs in input, to maintain alignment in multi column output.
+  [bug introduced in coreutils-6.9]
+
   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 22d032ba3f799b71aa802672cae5b1ba79db8789..5b003cb9a74b4b3926f2b91d94ad0f37479e691c 100644 (file)
--- a/src/pr.c
+++ b/src/pr.c
@@ -1237,6 +1237,8 @@ init_parameters (int number_of_files)
         col_sep_string = column_separator;
 
       truncate_lines = true;
+      if (! (col_sep_length == 1 && *col_sep_string == '\t'))
+        untabify_input = true;
       tabify_output = true;
     }
   else
index b7d868cf85ce26cf7a7e8585e44e7edcdc4e7108..d0ac405208d6bdd98eb9af5b8f3ddf81036ea028 100755 (executable)
@@ -466,6 +466,27 @@ push @Tests,
     {IN=>{2=>"m\tn\to\n"}},
     {IN=>{3=>"x\ty\tz\n"}},
      {OUT=>join("\t", qw(a b c m n o x y z)) . "\n"} ];
+# -s and -s$'\t' use different code paths
+push @Tests,
+   ['merge-w-tabs-sepstr', "-m -s'\t' -t",
+    {IN=>{1=>"a\tb\tc\n"}},
+    {IN=>{2=>"m\tn\to\n"}},
+    {IN=>{3=>"x\ty\tz\n"}},
+     {OUT=>join("\t", qw(a b c m n o x y z)) . "\n"} ];
+
+# Exercise a variant of the bug with pr -m -s (commit 553d347)
+# test 2 files, too (merging 3 files automatically aligns columns on TAB stops)
+push @Tests,
+   ['merge-2-w-tabs', '-m -s -t',
+    {IN=>{1=>"a\tb\tc\n"}},
+    {IN=>{2=>"m\tn\to\n"}},
+     {OUT=>join("\t", qw(a b c m n o)) . "\n"} ];
+# -s and -s$'\t' use different code paths
+push @Tests,
+   ['merge-2-w-tabs-sepstr', "-m -s'\t' -t",
+    {IN=>{1=>"a\tb\tc\n"}},
+    {IN=>{2=>"m\tn\to\n"}},
+     {OUT=>join("\t", qw(a b c m n o)) . "\n"} ];
 
 # This resulted in reading invalid memory before coreutils-8.26
 push @Tests,
@@ -474,6 +495,23 @@ push @Tests,
     {IN=>{2=>"a\n"}},
      {OUT=>"a\t\t\t\t  \t\t\ta\n"} ];
 
+# Exercise a bug with pr -t -2 (bug #46422)
+push @Tests,
+   ['mcol-w-tabs', '-t -2',
+    {IN=>"x\tx\tx\tx\tx\nx\tx\tx\tx\tx\n"},
+     {OUT=>"x\tx\tx\tx\tx   x\t    x\t    x\t    x\t    x\n"} ];
+
+# generalize case from commit 553d347 (problem results from -s, not -m)
+push @Tests,
+   ['mcol-w-tabs-w-tabsep', '-t -2 -s',
+    {IN=>"x\tx\tx\tx\tx\nx\tx\tx\tx\tx\n"},
+     {OUT=>"x\tx\tx\tx\tx\tx\tx\tx\tx\tx\n"} ];
+# -s and -s$'\t' use different code paths
+push @Tests,
+   ['mcol-w-tabs-w-tabsep-sepstr', "-t -2 -s'\t'",
+    {IN=>"x\tx\tx\tx\tx\nx\tx\tx\tx\tx\n"},
+     {OUT=>"x\tx\tx\tx\tx\tx\tx\tx\tx\tx\n"} ];
+
 @Tests = triple_test \@Tests;
 
 my $save_temps = $ENV{DEBUG};