Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with small table and usize::MAX width. #62

Merged
merged 2 commits into from Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .circleci/config.yml
Expand Up @@ -12,9 +12,9 @@ jobs:
- run: cargo --version
- run: cargo build
- run: cargo test
build-1-49:
build-1-56:
docker:
- image: cimg/rust:1.49
- image: cimg/rust:1.56
steps:
- checkout
- run: cargo --version
Expand Down Expand Up @@ -54,5 +54,5 @@ workflows:
build:
jobs:
- "build-stable"
- "build-1-49"
- "build-1-56"
- "build-windows"
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -7,7 +7,7 @@ repository = "https://github.com/jugglerchris/rust-html2text/"
readme = "README.md"
documentation = "https://docs.rs/html2text/"
edition = "2018"
rust-version = "1.49"
rust-version = "1.56"

keywords = ["html", "text"]
license = "MIT"
Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Expand Up @@ -1405,7 +1405,13 @@ fn render_table_tree<T: Write, R: Renderer>(
0
} else {
min(sz.size,
max(sz.size * width / tot_size, sz.min_width))
if usize::MAX/width <= sz.size {
// The provided width is too large to multiply by width,
// so do it the other way around.
max((width / tot_size) * sz.size, sz.min_width)
} else {
max(sz.size * width / tot_size, sz.min_width)
})
}
})
.collect()
Expand Down
2 changes: 1 addition & 1 deletion src/render/text_renderer.rs
Expand Up @@ -1172,7 +1172,7 @@ impl<D: TextDecorator> Renderer for TextRenderer<D> {
.map(|&(_, ref v)| v.len())
.max()
.unwrap_or(0);
let spaces: String = (0..self.width).map(|_| ' ').collect();
let spaces: String = (0..tot_width).map(|_| ' ').collect();
let last_cellno = line_sets.len() - 1;
for i in 0..cell_height {
let mut line = TaggedLine::new();
Expand Down
8 changes: 8 additions & 0 deletions src/tests.rs
Expand Up @@ -1303,3 +1303,11 @@ der
─────
", 5);
}

#[test]
fn test_max_width() {
let html = r#"<table><td><p>3,266</p>"#;
let decorator = crate::render::text_renderer::PlainDecorator::new();
let text = from_read_with_decorator(html.as_bytes(), usize::MAX, decorator.clone());
println!("{}", text);
}