Skip to content

Truly independent web browser

LibWeb: Don’t take a clamped block-level image for an atomic inline

sideshowbarker2c402a3b1353
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 960e353b71f..a93d555c807 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -2161,7 +2161,9 @@ impl<'context> InlineFormattingContext<'context> {
x: x + relative_insets.offset_x,
y: y + relative_insets.offset_y,
};
- if fragment.is_atomic_inline {
+ // A replaced element counts as atomic even when it's block-level, but a block-level box on a line
+ // interrupted for it was laid out and placed as a block, not as an atomic inline.
+ if fragment.is_atomic_inline && !line.has_block_level_box {
atomic_inlines_after_clamp_point.push((fragment.layout_node, position));
} else {
let (width, height) = fragment.size();
diff --git a/Tests/LibWeb/Crash/Layout/line-clamp-block-level-replaced-element-in-inline.html b/Tests/LibWeb/Crash/Layout/line-clamp-block-level-replaced-element-in-inline.html
new file mode 100644
index 00000000000..a3a5d8c44bf
--- /dev/null
+++ b/Tests/LibWeb/Crash/Layout/line-clamp-block-level-replaced-element-in-inline.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<style>
+ .clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; width: 80px; }
+</style>
+<div class="clamp"><span>one two three four<img style="display: block"></span></div>
+<span class="clamp"><span><a href="#"><span>one two three four<img width="0" height="0" style="display: block"></span></a></span></span>
diff --git a/Tests/LibWeb/Ref/expected/line-clamp-hides-block-level-replaced-element-in-inline-ref.html b/Tests/LibWeb/Ref/expected/line-clamp-hides-block-level-replaced-element-in-inline-ref.html
new file mode 100644
index 00000000000..875cbf6d70d
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/line-clamp-hides-block-level-replaced-element-in-inline-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<style>
+ * { margin: 0; }
+ div { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; width: 80px; font: 16px/20px monospace; }
+</style>
+<div><span>one two three four</span></div>
diff --git a/Tests/LibWeb/Ref/input/line-clamp-hides-block-level-replaced-element-in-inline.html b/Tests/LibWeb/Ref/input/line-clamp-hides-block-level-replaced-element-in-inline.html
new file mode 100644
index 00000000000..78586a296b7
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/line-clamp-hides-block-level-replaced-element-in-inline.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/line-clamp-hides-block-level-replaced-element-in-inline-ref.html" />
+<style>
+ * { margin: 0; }
+ div { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; width: 80px; font: 16px/20px monospace; }
+ img { display: block; width: 20px; height: 20px; }
+</style>
+<div><span>one two three four<img src="data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2220%22 height=%2220%22%3E%3Crect width=%2220%22 height=%2220%22 fill=%22red%22/%3E%3C/svg%3E"></span></div>