This commit is contained in:
@@ -11,6 +11,19 @@ pub fn sanitize_terminal_text(value: &str) -> String {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn sanitize_editor_text(value: &str) -> String {
|
||||
value
|
||||
.chars()
|
||||
.map(|character| {
|
||||
if character == '\n' || !character.is_control() {
|
||||
character
|
||||
} else {
|
||||
' '
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -22,4 +35,12 @@ mod tests {
|
||||
"safe [31m text"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn editor_sanitizer_preserves_newlines() {
|
||||
assert_eq!(
|
||||
sanitize_editor_text("first\nsecond\u{1b}[31m"),
|
||||
"first\nsecond [31m"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user