events: Escape HTML reserved characters in plain text reply fallback
This commit is contained in:
parent
806d389e13
commit
34b549f89f
@ -55,11 +55,28 @@ fn get_quotes(
|
||||
)
|
||||
}
|
||||
|
||||
fn formatted_or_plain_body<'a>(formatted: Option<&'a FormattedBody>, body: &'a str) -> &'a str {
|
||||
fn formatted_or_plain_body(formatted: Option<&FormattedBody>, body: &str) -> String {
|
||||
if let Some(formatted_body) = formatted {
|
||||
&formatted_body.body
|
||||
formatted_body.body.clone()
|
||||
} else {
|
||||
body
|
||||
let mut escaped_body = String::with_capacity(body.len());
|
||||
for c in body.chars() {
|
||||
let s = match c {
|
||||
'&' => Some("&"),
|
||||
'<' => Some("<"),
|
||||
'>' => Some(">"),
|
||||
'"' => Some("""),
|
||||
'\'' => Some("'"),
|
||||
'\n' => Some("<br>"),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(s) = s {
|
||||
escaped_body.push_str(s);
|
||||
} else {
|
||||
escaped_body.push(c);
|
||||
}
|
||||
}
|
||||
escaped_body
|
||||
}
|
||||
}
|
||||
|
||||
@ -113,7 +130,7 @@ mod tests {
|
||||
<a href=\"https://matrix.to/#/!n8f893n9:example.com/$1598361704261elfgc:localhost\">In reply to</a> \
|
||||
<a href=\"https://matrix.to/#/@alice:example.com\">@alice:example.com</a>\
|
||||
<br>\
|
||||
multi\nline\
|
||||
multi<br>line\
|
||||
</blockquote>\
|
||||
</mx-reply>"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user