1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

cksum: also handle the case when the line start with ' \'

This commit is contained in:
Sylvestre Ledru 2024-05-15 11:46:58 +02:00
parent 58c2b5d421
commit 9c52ca8d55
2 changed files with 20 additions and 1 deletions

View file

@ -422,7 +422,7 @@ where
// 1. <algo>[-<bits>] (<filename>) = <checksum> // 1. <algo>[-<bits>] (<filename>) = <checksum>
// algo must be uppercase or b (for blake2b) // algo must be uppercase or b (for blake2b)
// 2. <checksum> [* ]<filename> // 2. <checksum> [* ]<filename>
let regex_pattern = r"^(?P<algo>[A-Z0-9b]+)(-(?P<bits>\d+))?\s?\((?P<filename1>.*)\) = (?P<checksum1>[a-fA-F0-9]+)$|^(?P<checksum2>[a-fA-F0-9]+)\s[* ](?P<filename2>.*)"; let regex_pattern = r"^\s*\\?(?P<algo>[A-Z0-9b]+)(-(?P<bits>\d+))?\s?\((?P<filename1>.*)\) = (?P<checksum1>[a-fA-F0-9]+)$|^(?P<checksum2>[a-fA-F0-9]+)\s[* ](?P<filename2>.*)";
let re = Regex::new(regex_pattern).unwrap(); let re = Regex::new(regex_pattern).unwrap();
// if cksum has several input files, it will print the result for each file // if cksum has several input files, it will print the result for each file

View file

@ -809,6 +809,25 @@ fn test_cksum_check_space() {
.stderr_contains("line is improperly formatted"); .stderr_contains("line is improperly formatted");
} }
#[test]
fn test_cksum_check_leading_info() {
let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
at.touch("f");
at.write("CHECKSUM", "\
\\SHA384 (f) = 38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b\n\
\\BLAKE2b (f) = 786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce\n\
\\BLAKE2b-384 (f) = b32811423377f52d7862286ee1a72ee540524380fda1724a6f25d7978c6fd3244a6caf0498812673c5e05ef583825100\n\
\\SM3 (f) = 1ab21d8355cfa17f8e61194831e81a8f22bec8c728fefb747ed035eb5082aa2b\n");
scene
.ucmd()
.arg("--check")
.arg("CHECKSUM")
.succeeds()
.stdout_contains("f: OK\nf: OK\nf: OK\nf: OK\n");
}
#[test] #[test]
fn test_cksum_check() { fn test_cksum_check() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());