diff --git a/src/dehtml.rs b/src/dehtml.rs
index 152c01865..f80600c17 100644
--- a/src/dehtml.rs
+++ b/src/dehtml.rs
@@ -20,18 +20,18 @@ enum AddText {
YesPreserveLineEnds,
}
-// dehtml() returns way too many newlines; however, an optimisation on this issue is not needed as
-// the newlines are typically removed in further processing by the caller
-pub fn dehtml(buf: &str) -> String {
+/// dehtml() returns way too many newlines; however, an optimisation on this issue is not needed as
+/// the newlines are typically removed in further processing by the caller
+pub fn dehtml(buf: &str) -> Option {
let s = dehtml_quick_xml(buf);
if !s.trim().is_empty() {
- return s;
+ return Some(s);
}
let s = dehtml_manually(buf);
if !s.trim().is_empty() {
- return s;
+ return Some(s);
}
- buf.to_string()
+ None
}
pub fn dehtml_quick_xml(buf: &str) -> String {
@@ -220,21 +220,23 @@ mod tests {
"",
"[](https://get.delta.chat/)",
),
- ("", ""),
("\nfat text", "*fat text*"),
// Invalid html (at least DC should show the text if the html is invalid):
("\nsome text", "some text"),
- ("", ""),
];
for (input, output) in cases {
- assert_eq!(simplify(dehtml(input), true).0, output);
+ assert_eq!(simplify(dehtml(input).unwrap(), true).0, output);
+ }
+ let none_cases = vec![" ", ""];
+ for input in none_cases {
+ assert_eq!(dehtml(input), None);
}
}
#[test]
fn test_dehtml_parse_br() {
let html = "\r\r\nline1
\r\n\r\n\r\rline2
line3\n\r";
- let plain = dehtml(html);
+ let plain = dehtml(html).unwrap();
assert_eq!(plain, "line1\n\r\r\rline2\nline3");
}
@@ -242,7 +244,7 @@ mod tests {
#[test]
fn test_dehtml_parse_href() {
let html = "text]>text bold]]>";
- let plain = dehtml(html);
+ let plain = dehtml(html).unwrap();
assert_eq!(plain, "text *bold*<>");
}
@@ -260,7 +262,7 @@ mod tests {
let html =
"<>"'& äÄöÖüÜß fooÆçÇ ♦&noent;";
- let plain = dehtml(html);
+ let plain = dehtml(html).unwrap();
assert_eq!(
plain,
@@ -283,7 +285,7 @@ mod tests {