]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cut: treat -b2-,3- like -b2-, not like -b3-
authorJim Meyering <jim@meyering.net>
Sat, 24 Nov 2012 07:09:10 +0000 (23:09 -0800)
committerJim Meyering <jim@meyering.net>
Sat, 24 Nov 2012 23:23:28 +0000 (15:23 -0800)
* src/cut.c (set_fields): When two right-open-ended ranges are
specified, don't blindly let the latter one take precedence over
the former.  Instead, use the union of the ranges.
* tests/misc/cut.pl: Add tests to exercise this.
* NEWS (Bug fixes): Mention it.
Reported by Marcel Böhme in http://bugs.gnu.org/12966
Thanks to Berhard Voelker for catching log and NEWS typos.

NEWS
src/cut.c
tests/misc/cut.pl

diff --git a/NEWS b/NEWS
index 8529216afd8be58fe9a0d90f2f74d832f9b890e3..63583c1a776a9d4ae2c6f9a158dc39027f480303 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -14,6 +14,10 @@ GNU coreutils NEWS                                    -*- outline -*-
   Instead, cut now fails and emits an appropriate diagnostic.
   [This bug was present in "the beginning".]
 
+  cut now handles overlapping to-EOL ranges properly.  Before, it would
+  interpret "-b2-,3-" like "-b3-".  Now it's treated like "-b2-".
+  [This bug was present in "the beginning".]
+
   install -m M SOURCE DEST no longer has a race condition where DEST's
   permissions are temporarily derived from SOURCE instead of from M.
 
index 2a571483ad4eef0083c2472c0275061cd0c6fc62..b464840d74a19e8ecf6f8975af00cbb528f6acd7 100644 (file)
--- a/src/cut.c
+++ b/src/cut.c
@@ -391,8 +391,10 @@ set_fields (const char *fieldstr)
                  In any case, 'initial' contains the start of the range. */
               if (!rhs_specified)
                 {
-                  /* 'n-'.  From 'initial' to end of line. */
-                  eol_range_start = initial;
+                  /* 'n-'.  From 'initial' to end of line.  If we've already
+                     seen an M- range, ignore subsequent N- unless N < M.  */
+                  if (eol_range_start == 0 || initial < eol_range_start)
+                    eol_range_start = initial;
                   field_found = true;
                 }
               else
index cd5655569c0d0b8bc2470cf2e2d57225cad7f1e0..cb4781a7d19649bc9dcd149f8a80f435d5765bc6 100755 (executable)
@@ -163,6 +163,9 @@ my @Tests =
   ['big-unbounded-b', '--output-d=:', '-b1234567890-', {IN=>''}, {OUT=>''}],
   ['big-unbounded-c', '--output-d=:', '-c1234567890-', {IN=>''}, {OUT=>''}],
   ['big-unbounded-f', '--output-d=:', '-f1234567890-', {IN=>''}, {OUT=>''}],
+
+  ['overlapping-unbounded-1', '-b3-,2-', {IN=>"1234\n"}, {OUT=>"234\n"}],
+  ['overlapping-unbounded-2', '-b2-,3-', {IN=>"1234\n"}, {OUT=>"234\n"}],
  );
 
 if ($mb_locale ne 'C')