mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-10 06:54:12 +00:00
Fix sanitize_html whitespaces (#3829)
This commit is contained in:
parent
bed9474cf0
commit
d81fb987aa
1 changed files with 8 additions and 4 deletions
|
@ -797,12 +797,14 @@ pub fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError
|
|||
/// Sanitize HTML with default options. Additionally, dont allow bypassing markdown
|
||||
/// links and images
|
||||
pub fn sanitize_html(data: &str) -> String {
|
||||
let sanitized = ammonia::Builder::default()
|
||||
ammonia::Builder::default()
|
||||
.rm_tags(&["a", "img"])
|
||||
.clean(data)
|
||||
.to_string();
|
||||
// restore markdown quotes
|
||||
sanitized.replace(">", ">")
|
||||
.to_string()
|
||||
// restore markdown quotes
|
||||
.replace(">", ">")
|
||||
// restore white space
|
||||
.replace(" ", " ")
|
||||
}
|
||||
|
||||
pub fn sanitize_html_opt(data: &Option<String>) -> Option<String> {
|
||||
|
@ -839,5 +841,7 @@ mod tests {
|
|||
assert_eq!(sanitized, " hello");
|
||||
let sanitized = sanitize_html("<img src='http://example.com'> test");
|
||||
assert_eq!(sanitized, " test");
|
||||
let sanitized = sanitize_html("Hello World");
|
||||
assert_eq!(sanitized, "Hello World");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue