Skip to content

Truly independent web browser

LibWeb: Don’t take a flex or grid button’s item for its content box

sideshowbarkere91afa3003c1
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
index 92f382834ba..a639a965fd0 100644
--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs
@@ -4894,7 +4894,12 @@ impl LayoutNodeArena {
facts |= AncestorFact::ParentIsUnfloatedFlowContainer as u8;
}
if super::node_facts::has_flag(data, NodeFlag::Anonymous) {
- if super::node_facts::has_flag(parent_data, NodeFlag::UsesButtonLayout) {
+ // The contents of a box that uses button layout are wrapped only when its display is neither flex nor grid,
+ // as wrap_button_contents_if_needed() does it. A flex or grid button's anonymous child is a flex or grid item.
+ if super::node_facts::has_flag(parent_data, NodeFlag::UsesButtonLayout)
+ && !parent_style
+ .is_some_and(|style| style.display().is_grid_inside() || style.display().is_flex_inside())
+ {
facts |= AncestorFact::IsAnonymousButtonContentWrapper as u8;
}
if super::node_facts::has_ancestor_fact(parent_data, AncestorFact::IsAnonymousButtonContentWrapper) {
diff --git a/Tests/LibWeb/Crash/Layout/flex-button-with-aspect-ratio-and-before-content.html b/Tests/LibWeb/Crash/Layout/flex-button-with-aspect-ratio-and-before-content.html
new file mode 100644
index 00000000000..34fa11eebf5
--- /dev/null
+++ b/Tests/LibWeb/Crash/Layout/flex-button-with-aspect-ratio-and-before-content.html
@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<style>
+ button {
+ display: flex;
+ aspect-ratio: 1;
+ }
+ button::before {
+ content: "x";
+ }
+</style>
+<button></button>