Skip to content

Commit

Permalink
Avoid a potential division by a 0 width.
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglerchris committed Nov 5, 2023
1 parent eabf97e commit baf903d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1424,7 +1424,7 @@ fn render_table_tree<T: Write, D: TextDecorator>(
+ col_sizes.len().saturating_sub(1);
let width = renderer.width();

let vert_row = min_size > width;
let vert_row = min_size > width || width == 0;

let mut col_widths: Vec<usize> = if !vert_row {
col_sizes
Expand Down
62 changes: 62 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,68 @@ fn test_empty_cols() {
);
}

#[test]
fn test_empty_table() {
test_html(
br##"
<table></table>
"##,
r#"
"#,
12,
);
}

#[test]
fn test_table_empty_single_row() {
test_html(
br##"
<table><tr></tr></table>
"##,
r#"
"#,
12,
);
}

#[test]
fn test_table_empty_single_row_empty_cell() {
test_html(
br##"
<table><tr><td></td></tr></table>
"##,
r#"
"#,
12,
);
}

#[test]
fn test_renderer_zero_width() {
test_html(
br##"<ul><li><table><tr><td>x</td></tr></table></li></ul>
"##,
// Unfortunately the "x" ends up not being rendered as it doesn't fit.
r#"*
"#,
2,
);
}

#[test]
fn test_ul_tiny_table() {
test_html(
br##"<ul><li><table><tr><td>x</td></tr></table></li></ul>
"##,
r#"* ─
x
"#,
12,
);
}

#[test]
fn test_issue_54_oob() {
test_html(
Expand Down

0 comments on commit baf903d

Please sign in to comment.