Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: non-ASCII character breaks remove_trailing_blanks #9

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/validate.rs
Original file line number Diff line number Diff line change
@@ -190,9 +190,7 @@ fn remove_ascii_ctrl(t: &mut String) {
}

fn remove_trailing_blanks(t: &mut String) {
if let Some(last) = t.rfind(|c| c != ' ') {
t.truncate(last + 1);
}
t.truncate(t.trim_end().len());
}

/// Replace all ASCII control codes with blank.
@@ -775,18 +773,23 @@ mod tests {
let mut s1 = String::from("");
let mut s2 = String::from(" a b c ");
let mut s3 = String::from("\0a\tb\rc\r\n");
let mut s4 = String::from("abc\u{b3}");
remove_ascii_ctrl(&mut s1);
remove_ascii_ctrl(&mut s2);
remove_ascii_ctrl(&mut s3);
remove_ascii_ctrl(&mut s4);
assert_eq!(s1, String::from(""));
assert_eq!(s2, String::from(" a b c "));
assert_eq!(s3, String::from(" a b c "));
assert_eq!(s4, String::from("abc\u{b3}"));
remove_trailing_blanks(&mut s1);
remove_trailing_blanks(&mut s2);
remove_trailing_blanks(&mut s3);
remove_trailing_blanks(&mut s4);
assert_eq!(s1, String::from(""));
assert_eq!(s2, String::from(" a b c"));
assert_eq!(s3, String::from(" a b c"));
assert_eq!(s4, String::from("abc\u{b3}"));
}

#[test]
Loading