From 38a374858ef11d66e2afe5d9170c72c5f58bc8d5 Mon Sep 17 00:00:00 2001 From: Pierre Dubouilh Date: Mon, 25 May 2026 17:11:08 +0200 Subject: [PATCH] tighten clf regex --- src/clf.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/clf.rs b/src/clf.rs index 2e6783d..945fb7b 100644 --- a/src/clf.rs +++ b/src/clf.rs @@ -6,7 +6,7 @@ use std::{net::IpAddr, str::FromStr}; lazy_static! { static ref RE_IP: Regex = Regex::new(r"^(\S+)\s").unwrap(); - static ref RE_STATUS: Regex = Regex::new(r"(\d+)\s(\w+)$").unwrap(); + static ref RE_STATUS: Regex = Regex::new(r"(\d+)\s+\S+\s*$").unwrap(); } #[allow(clippy::bind_instead_of_map)] @@ -69,6 +69,22 @@ mod tests { }) } + #[test] + fn bodyless() { + // CLF uses `-` for absent body bytes, both branches must still parse + let bad = "8.8.8.8 - p [25/Sep/2021:13:49:56 +0200] \"GET / HTTP/2.0\" 401 -"; + match parse(bad, &vec![401, 429]).unwrap() { + ParsingStatus::BadEntry(_) => {} + _ => panic!("bad parsing"), + } + + let ok = "8.8.8.8 - p [25/Sep/2021:13:49:56 +0200] \"GET / HTTP/2.0\" 304 -"; + match parse(ok, &vec![401, 429]).unwrap() { + ParsingStatus::OkEntry => {} + _ => panic!("bad parsing"), + } + } + #[test] fn malformed() { let vectors = [