Repository: jugglerchris/rust-html2text (rust)

Issue:
Panic
In commit 5b9d69f a regression was introduced, since then this fragment panics
```
<html>
    <body>
        <ul>
            <table><tr></tr></table>
        </ul>
    </body>
</html>
```


Pull request:
Panic empty table
Fixes #164 

Patch:
diff --git a/examples/html2term.rs b/examples/html2term.rs
index 92e8a91..8df19bd 100644
--- a/examples/html2term.rs
+++ b/examples/html2term.rs
@@ -1,14 +1,9 @@
 #[cfg(unix)]
 extern crate argparse;
 #[cfg(unix)]
-extern crate termion;
-#[cfg(unix)]
 extern crate unicode_width;
 #[cfg(unix)]
 mod top {
-    use ::html2text;
-    use ::std;
-    use ::termion;
     use argparse::{ArgumentParser, Store};
     use html2text::render::{RichAnnotation, TaggedLine, TaggedLineElement};
     use std::collections::HashMap;
diff --git a/src/css/parser.rs b/src/css/parser.rs
index ba3ca06..edf39e7 100644
--- a/src/css/parser.rs
+++ b/src/css/parser.rs
@@ -225,7 +225,7 @@ fn ident_escape(s: &str) -> IResult<&str, char> {
     match chars.next() {
         None => {
             // EOF: return replacement char
-            Ok((&rest, '\u{fffd}'))
+            Ok((rest, '\u{fffd}'))
         }
         Some((i, c)) if c.is_hex_digit() => {
             // Option 1: up to 6 hex digits.
diff --git a/src/lib.rs b/src/lib.rs
index 76b674e..49793d0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1801,13 +1801,9 @@ fn render_table_tree<T: Write, D: TextDecorator>(
                 .saturating_sub(1)
     };
 
-    if table_width == 0 {
-        return Ok(TreeMapResult::Nothing);
-    }
-
     renderer.start_block()?;
 
-    if renderer.options.draw_borders {
+    if table_width != 0 && renderer.options.draw_borders {
         renderer.add_horizontal_border_width(table_width)?;
     }
 
diff --git a/src/markup5ever_rcdom.rs b/src/markup5ever_rcdom.rs
index 19d726a..ff8b371 100644
--- a/src/markup5ever_rcdom.rs
+++ b/src/markup5ever_rcdom.rs
@@ -42,7 +42,6 @@ extern crate tendril;
 use std::borrow::Cow;
 use std::cell::{Cell, RefCell};
 use std::collections::{HashSet, VecDeque};
-use std::default::Default;
 use std::fmt;
 use std::io;
 use std::mem;
diff --git a/src/render/text_renderer.rs b/src/render/text_renderer.rs
index 7fa060b..74134a3 100644
--- a/src/render/text_renderer.rs
+++ b/src/render/text_renderer.rs
@@ -1032,7 +1032,7 @@ impl<D: TextDecorator> SubRenderer<D> {
         let mut result = String::new();
         for line in &self.lines {
             result += &line.to_string();
-            result.push_str("\n");
+            result.push('\n');
         }
         result
     }


Test patch:
diff --git a/src/tests.rs b/src/tests.rs
index 44e2c6c..ea9f481 100644
--- a/src/tests.rs
+++ b/src/tests.rs
@@ -1128,14 +1128,14 @@ hi
     .take(rpt - 3)
     .collect::<Vec<_>>()
     .concat()
-        + &r#"──┬────
+        + r#"──┬────
 hi│hi  
   │////
   │──  
   │hi  
   │──  
 ──┴────
-"# + &repeat("──────────\n").take(rpt - 3).collect::<String>();
+"# + &"──────────\n".repeat(rpt - 3);
     test_html(html.as_bytes(), &result, 10);
 }
 
@@ -2011,6 +2011,20 @@ fn test_table_too_narrow() {
     from_read(tbl, 80);
 }
 
+#[test]
+fn test_empty_table_in_list() {
+    test_html(
+        b"
+<ul>
+  <table>
+    <tr></tr>
+  </table>
+</ul>",
+        "",
+        80,
+    );
+}
+
 #[cfg(feature = "css")]
 mod css_tests {
     use super::{test_html_coloured, test_html_css, test_html_style};