mirror of
https://github.com/soywod/himalaya.git
synced 2024-09-29 04:31:11 +00:00
improve msg sanitization (#280)
This commit is contained in:
parent
8919d03c60
commit
ee86afe756
|
@ -100,25 +100,41 @@ impl Msg {
|
||||||
.tags(HashSet::default())
|
.tags(HashSet::default())
|
||||||
.clean(&html)
|
.clean(&html)
|
||||||
.to_string();
|
.to_string();
|
||||||
// Replace ` ` by regular space
|
// Merge new line chars
|
||||||
let sanitized_html = Regex::new(r" ")
|
let sanitized_html = Regex::new(r"(\r?\n\s*){2,}")
|
||||||
|
.unwrap()
|
||||||
|
.replace_all(&sanitized_html, "\n\n")
|
||||||
|
.to_string();
|
||||||
|
// Replace tabulations and &npsp; by spaces
|
||||||
|
let sanitized_html = Regex::new(r"(\t| )")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.replace_all(&sanitized_html, " ")
|
.replace_all(&sanitized_html, " ")
|
||||||
.to_string();
|
.to_string();
|
||||||
// Merge new line chars
|
// Merge spaces
|
||||||
let sanitized_html = Regex::new(r"(\r?\n[\t ]*){2,}")
|
let sanitized_html = Regex::new(r" {2,}")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.replace_all(&sanitized_html, "\n\n")
|
.replace_all(&sanitized_html, " ")
|
||||||
.to_string();
|
.to_string();
|
||||||
// Decode HTML entities
|
// Decode HTML entities
|
||||||
let sanitized_html = html_escape::decode_html_entities(&sanitized_html).to_string();
|
let sanitized_html = html_escape::decode_html_entities(&sanitized_html).to_string();
|
||||||
|
|
||||||
sanitized_html
|
sanitized_html
|
||||||
} else {
|
} else {
|
||||||
let sanitized_plain = Regex::new(r"(\r?\n[\t ]*){2,}")
|
// Merge new line chars
|
||||||
|
let sanitized_plain = Regex::new(r"(\r?\n\s*){2,}")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.replace_all(&plain, "\n\n")
|
.replace_all(&plain, "\n\n")
|
||||||
.to_string();
|
.to_string();
|
||||||
|
// Replace tabulations by spaces
|
||||||
|
let sanitized_plain = Regex::new(r"\t")
|
||||||
|
.unwrap()
|
||||||
|
.replace_all(&sanitized_plain, " ")
|
||||||
|
.to_string();
|
||||||
|
// Merge spaces
|
||||||
|
let sanitized_plain = Regex::new(r" {2,}")
|
||||||
|
.unwrap()
|
||||||
|
.replace_all(&sanitized_plain, " ")
|
||||||
|
.to_string();
|
||||||
|
|
||||||
sanitized_plain
|
sanitized_plain
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue