diff --git a/src/uu/hashsum/src/hashsum.rs b/src/uu/hashsum/src/hashsum.rs index 8c574f066..597bca565 100644 --- a/src/uu/hashsum/src/hashsum.rs +++ b/src/uu/hashsum/src/hashsum.rs @@ -692,6 +692,10 @@ where Ok(l) => l, Err(e) => return Err(e.map_err_context(|| "failed to read file".to_string())), }; + if line.is_empty() { + // empty line, skip it + continue; + } let (ck_filename, sum, binary_check) = match gnu_re.captures(&line) { Some(caps) => { handle_captures(&caps, &bytes_marker, &mut bsd_reversed, &mut gnu_re)? diff --git a/tests/by-util/test_hashsum.rs b/tests/by-util/test_hashsum.rs index e5e3e1e98..535a4d0ba 100644 --- a/tests/by-util/test_hashsum.rs +++ b/tests/by-util/test_hashsum.rs @@ -457,6 +457,24 @@ fn test_with_escape_filename_zero_text() { assert!(stdout.contains("a\nb")); } +#[test] +fn test_check_empty_line() { + let scene = TestScenario::new(util_name!()); + let at = &scene.fixtures; + + at.touch("f"); + at.write( + "in.md5", + "d41d8cd98f00b204e9800998ecf8427e f\n\nd41d8cd98f00b204e9800998ecf8427e f\ninvalid\n\n", + ); + scene + .ccmd("md5sum") + .arg("--check") + .arg(at.subdir.join("in.md5")) + .fails() + .stderr_contains("WARNING: 1 line is improperly formatted"); +} + #[test] #[cfg(not(windows))] fn test_check_with_escape_filename() {