pub fn check_csv_injection(field: &str, row_count: usize) -> bool {
if let Some(first_char) = field.chars().next() {
if "=@".contains(first_char) {
let e_field = escape_special_chars(field);
eprintln!("Line {}, Potential CSV formula injection detected, filtered: {}", row_count, &e_field);
return true;
}
}
false
}
pub fn escape_special_chars(input: &str) -> String {
let mut result = input.to_string();
let special_chars = [
("\n", "\\n"),
("\t", "\\t"),
("\r", "\\r"),
("\"", "\\\""),
("'", "\\'"),
("\x08", "\\b"),
("\x0c", "\\f"),
("\x0b", "\\v"),
("\\", "\\\\"),
];
for (char, escaped_char) in special_chars.iter() {
result = result.replace(*char, *escaped_char);
}
result
}