Skip to content

Commit

Permalink
Merge pull request #165 from sftse/panic-empty-table
Browse files Browse the repository at this point in the history
Fix panic on empty table
  • Loading branch information
jugglerchris authored Sep 19, 2024
2 parents 0476d71 + 6f4ac52 commit 443c4fb
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
5 changes: 0 additions & 5 deletions examples/html2term.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/css/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 1 addition & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}

Expand Down
1 change: 0 additions & 1 deletion src/markup5ever_rcdom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/render/text_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 16 additions & 2 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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};
Expand Down

0 comments on commit 443c4fb

Please sign in to comment.