fix(html): keep widthless colgroups on cell-width fallback

This commit is contained in:
skylar taylor-barrick
2026-11-18 04:43:01 +01:00
parent c0edd96888
commit c255ab0e51
2 changed files with 18 additions and 1 deletions
+1 -1
View File
@@ -935,7 +935,7 @@ impl<'r> Builder<'r> {
ft.rows.retain(|r| !r.is_empty());
}
if !ft.rows.is_empty() {
if !col_widths.is_empty() && ft.cols() <= MAX_TABLE_COLS {
if col_widths.iter().any(Option::is_some) && ft.cols() <= MAX_TABLE_COLS {
let mut widths = vec![None; ft.cols()];
for (i, &cw) in col_widths.iter().take(ft.cols()).enumerate() {
if let Some(w) = cw {
+17
View File
@@ -1,5 +1,22 @@
use super::*;
#[test]
fn widthless_columns_do_not_change_cell_width_resolution() {
let widths = |columns: &str, cells: &str| {
let flow = parse(&format!("<table>{columns}<tr>{cells}</tr></table>"));
let FBlock::Table(table) = &flow.blocks[0] else { panic!("expected table") };
table.widths.clone()
};
let partial = "<td width='400'>x</td><td>y</td>";
let widthless = "<colgroup><col><col></colgroup>";
assert!(widths("", partial).is_empty());
assert_eq!(widths(widthless, partial), widths("", partial));
let complete = "<td width='40'>x</td><td width='80'>y</td>";
assert_eq!(widths(widthless, complete), vec![30.0, 60.0]);
// An explicitly declared column still enables the existing average-fill rule.
assert_eq!(widths("<colgroup><col style='width:100pt'><col></colgroup>", "<td>x</td><td>y</td>"), vec![100.0, 100.0]);
}
#[test]
fn numeric_entity_rejects_sign() {
assert_eq!(unescape("a&#+65;b"), "a&#+65;b");