mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
script: Clamp table spans according to the HTML specification (#36703)
Previously, spans were partially clamped during layout, but this means that accessing and setting these properties via script wouldn't behave according to the HTML specification. In addition, the value wasn't floored in layout, so could lead to panics. This change improves clamping and moves it to script. Testing: This change includes a new WPT test. Fixes #36699. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
b10fc49e8a
commit
0d21992edd
9 changed files with 177 additions and 75 deletions
|
@ -1019,15 +1019,16 @@ where
|
|||
DisplayLayoutInternal::TableCell => {
|
||||
// This value will already have filtered out rowspan=0
|
||||
// in quirks mode, so we don't have to worry about that.
|
||||
//
|
||||
// The HTML specification limits the parsed value of `rowspan` to
|
||||
// 65534 and `colspan` to 1000, so we also enforce the same limits
|
||||
// when dealing with arbitrary DOM elements (perhaps created via
|
||||
// script).
|
||||
let (rowspan, colspan) = if info.pseudo_element_type.is_none() {
|
||||
let node = info.node.to_threadsafe();
|
||||
let rowspan = node.get_rowspan().unwrap_or(1).min(65534) as usize;
|
||||
let colspan = node.get_colspan().unwrap_or(1).min(1000) as usize;
|
||||
let rowspan = node.get_rowspan().unwrap_or(1) as usize;
|
||||
let colspan = node.get_colspan().unwrap_or(1) as usize;
|
||||
|
||||
// The HTML specification clamps value of `rowspan` to [0, 65534] and
|
||||
// `colspan` to [1, 1000].
|
||||
assert!((1..=1000).contains(&colspan));
|
||||
assert!((0..=65534).contains(&rowspan));
|
||||
|
||||
(rowspan, colspan)
|
||||
} else {
|
||||
(1, 1)
|
||||
|
@ -1140,21 +1141,19 @@ fn add_column<'dom, Node: NodeExt<'dom>>(
|
|||
is_anonymous: bool,
|
||||
) -> ArcRefCell<TableTrack> {
|
||||
let span = if column_info.pseudo_element_type.is_none() {
|
||||
column_info
|
||||
.node
|
||||
.to_threadsafe()
|
||||
.get_span()
|
||||
.unwrap_or(1)
|
||||
.min(1000) as usize
|
||||
column_info.node.to_threadsafe().get_span().unwrap_or(1)
|
||||
} else {
|
||||
1
|
||||
};
|
||||
|
||||
// The HTML specification clamps value of `span` for `<col>` to [1, 1000].
|
||||
assert!((1..=1000).contains(&span));
|
||||
|
||||
let column = ArcRefCell::new(TableTrack {
|
||||
base: LayoutBoxBase::new(column_info.into(), column_info.style.clone()),
|
||||
group_index,
|
||||
is_anonymous,
|
||||
});
|
||||
collection.extend(repeat(column.clone()).take(span));
|
||||
collection.extend(repeat(column.clone()).take(span as usize));
|
||||
column
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue