mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 09:26:29 +03:00
fix(dehtml): skip links with empty text
This commit is contained in:
@@ -165,9 +165,13 @@ fn dehtml_endtag_cb(event: &BytesEnd, dehtml: &mut Dehtml) {
|
|||||||
}
|
}
|
||||||
"a" => {
|
"a" => {
|
||||||
if let Some(ref last_href) = dehtml.last_href.take() {
|
if let Some(ref last_href) = dehtml.last_href.take() {
|
||||||
dehtml.strbuilder += "](";
|
if dehtml.strbuilder.ends_with('[') {
|
||||||
dehtml.strbuilder += last_href;
|
dehtml.strbuilder.truncate(dehtml.strbuilder.len() - 1);
|
||||||
dehtml.strbuilder += ")";
|
} else {
|
||||||
|
dehtml.strbuilder += "](";
|
||||||
|
dehtml.strbuilder += last_href;
|
||||||
|
dehtml.strbuilder += ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"b" | "strong" => {
|
"b" | "strong" => {
|
||||||
@@ -323,9 +327,10 @@ mod tests {
|
|||||||
("& bar", "& bar"),
|
("& bar", "& bar"),
|
||||||
// Despite missing ', this should be shown:
|
// Despite missing ', this should be shown:
|
||||||
("<a href='/foo.png>Hi</a> ", "Hi "),
|
("<a href='/foo.png>Hi</a> ", "Hi "),
|
||||||
|
("No link: <a href='https://get.delta.chat/'/>", "No link: "),
|
||||||
(
|
(
|
||||||
"<a href='https://get.delta.chat/'/>",
|
"No link: <a href='https://get.delta.chat/'></a>",
|
||||||
"[](https://get.delta.chat/)",
|
"No link: ",
|
||||||
),
|
),
|
||||||
("<!doctype html>\n<b>fat text</b>", "*fat text*"),
|
("<!doctype html>\n<b>fat text</b>", "*fat text*"),
|
||||||
// Invalid html (at least DC should show the text if the html is invalid):
|
// Invalid html (at least DC should show the text if the html is invalid):
|
||||||
|
|||||||
Reference in New Issue
Block a user