fix(pii): remove lookahead from hostname regex, fix fmt in analysis test

Rust's `regex` crate does not support lookaround assertions. The hostname
pattern `(?=.{1,253}\b)` caused a panic on every `PiiDetector::new()` call,
failing all four PII detector tests in CI (rust-fmt-check, rust-clippy,
rust-tests). Removed the lookahead; the remaining pattern correctly matches
valid FQDNs without the RFC 1035 length pre-check.

Also reformatted analysis.rs:253 to satisfy `rustfmt` (line break after `=`).

All 127 Rust tests pass and `cargo fmt --check` and `cargo clippy -- -D
warnings` are clean.
This commit is contained in:
Shaun Arman 2026-04-05 09:59:19 -05:00
parent 281e676ad1
commit 0a25ca7692
2 changed files with 6 additions and 6 deletions

View File

@ -250,10 +250,8 @@ mod tests {
#[test]
fn test_validate_log_file_path_accepts_small_file() {
let file_path = std::env::temp_dir().join(format!(
"tftsr-analysis-test-{}.log",
uuid::Uuid::now_v7()
));
let file_path =
std::env::temp_dir().join(format!("tftsr-analysis-test-{}.log", uuid::Uuid::now_v7()));
std::fs::write(&file_path, "hello").unwrap();
let result = validate_log_file_path(file_path.to_string_lossy().as_ref());
assert!(result.is_ok());

View File

@ -75,8 +75,10 @@ pub fn get_patterns() -> Vec<(PiiType, Regex)> {
// Hostname / FQDN
(
PiiType::Hostname,
Regex::new(r"\b(?=.{1,253}\b)(?:[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,63}\b")
.unwrap(),
Regex::new(
r"\b(?:[A-Za-z0-9](?:[A-Za-z0-9\-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z]{2,63}\b",
)
.unwrap(),
),
]
}