#[must_use]
pub fn sanitize_task_prompt(s: &str) -> String {
s.chars()
.take(512)
.filter(|&c| c >= '\x20' || c == '\n' || c == '\t')
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn strips_control_chars() {
assert_eq!(sanitize_task_prompt("hello\x01\x00world"), "helloworld");
}
#[test]
fn preserves_newline_and_tab() {
assert_eq!(
sanitize_task_prompt("line1\nline2\ttab"),
"line1\nline2\ttab"
);
}
#[test]
fn truncates_at_512_code_points() {
let long = "a".repeat(1000);
assert_eq!(sanitize_task_prompt(&long).chars().count(), 512);
}
#[test]
fn handles_multibyte_boundary() {
let s: String = "é".repeat(600);
let result = sanitize_task_prompt(&s);
assert_eq!(result.chars().count(), 512);
}
}