]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
digest: ignore empty lines when checking
authorPádraig Brady <P@draigBrady.com>
Thu, 16 Sep 2021 11:29:12 +0000 (12:29 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 16 Sep 2021 19:39:28 +0000 (20:39 +0100)
* src/digest.c (digest_check): Treat empty lines like comments,
as commented checksum files very often have empty lines.
* tests/misc/md5sum.pl: Adjust accordingly.

src/digest.c
tests/misc/md5sum.pl

index 9ee37a104000aeca350b273f18af60129223f140..9398a133ecf5bb251de47ffb1ab096d62cc3336c 100644 (file)
@@ -1073,6 +1073,11 @@ digest_check (char const *checkfile_name)
       line_length -= line[line_length - 1] == '\n';
       /* Remove any trailing carriage return.  */
       line_length -= line[line_length - (0 < line_length)] == '\r';
+
+      /* Ignore empty lines.  */
+      if (line_length == 0)
+        continue;
+
       line[line_length] = '\0';
 
       if (! (split_3 (line, line_length, &hex_digest, &binary, &filename)
index 09c2174f551a5552147e4c7f28eb0dd979226712..64b67deb32fecf5eb36402d76470d253403cacf8 100755 (executable)
@@ -53,18 +53,15 @@ my @Tests =
                                 {IN=> {'f.md5' => "$degenerate  f\r\n"}},
                                 {OUT=>"f: OK\n"}],
 
-     # Same as above, but with an added empty line, to provoke --strict.
+     # Same as above, but with an added empty line, to test --strict.
      ['ck-strict-1', '--check --strict', {AUX=> {f=> ''}},
                                 {IN=> {'f.md5' => "$degenerate  f\n\n"}},
-                                {OUT=>"f: OK\n"},
-                                {ERR=>"md5sum: "
-                                 . "WARNING: 1 line is improperly formatted\n"},
-                                {EXIT=> 1}],
+                                {OUT=>"f: OK\n"}],
 
      # As above, but with the invalid line first, to ensure that following
      # lines are processed in spite of the preceding invalid input line.
      ['ck-strict-2', '--check --strict', {AUX=> {f=> ''}},
-                                {IN=> {'in.md5' => "\n$degenerate  f\n"}},
+                                {IN=> {'in.md5' => "ERR\n$degenerate  f\n"}},
                                 {OUT=>"f: OK\n"},
                                 {ERR=>"md5sum: "
                                  . "WARNING: 1 line is improperly formatted\n"},