Remove newlines from group names, chat names and the displayname (#1845)

This commit is contained in:
Hocuri
2020-08-20 09:05:08 +02:00
committed by GitHub
parent 3faf968b7c
commit b9ca7b8ace
4 changed files with 29 additions and 6 deletions

View File

@@ -612,6 +612,16 @@ pub(crate) fn listflags_has(listflags: u32, bitindex: usize) -> bool {
(listflags & bitindex) == bitindex
}
/// Makes sure that a user input that is not supposed to contain newlines does not contain newlines.
pub(crate) fn improve_single_line_input(input: impl AsRef<str>) -> String {
input
.as_ref()
.replace("\n", " ")
.replace("\r", " ")
.trim()
.to_string()
}
#[cfg(test)]
mod tests {
use super::*;
@@ -960,4 +970,10 @@ mod tests {
assert_eq!(w, 100);
assert_eq!(h, 50);
}
#[test]
fn test_improve_single_line_input() {
assert_eq!(improve_single_line_input("Hi\naiae "), "Hi aiae");
assert_eq!(improve_single_line_input("\r\nahte\n\r"), "ahte");
}
}