From bd6c97deed6c11208d60fa0b19b2da528bcc4907 Mon Sep 17 00:00:00 2001 From: Erik Auerswald Date: Mon, 15 Feb 2021 21:21:17 +0000 Subject: [PATCH] pr: fix alignment of input tabs to multiple columns 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 | 3 +++ src/pr.c | 2 ++ tests/pr/pr-tests.pl | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/NEWS b/NEWS index 778be3e80c..79bb25e860 100644 --- 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] diff --git a/src/pr.c b/src/pr.c index 22d032ba3f..5b003cb9a7 100644 --- 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 diff --git a/tests/pr/pr-tests.pl b/tests/pr/pr-tests.pl index b7d868cf85..d0ac405208 100755 --- a/tests/pr/pr-tests.pl +++ b/tests/pr/pr-tests.pl @@ -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}; -- 2.47.2