Skip to content

Truly independent web browser

LibWeb: Treat an image’s percentage height with no basis as auto

sideshowbarker8604dbfd520f
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 9ec9cfe2688..02f2c63ea6f 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -1309,7 +1309,13 @@ impl<'pass> SizingContext<'pass> {
formatting_context::CyclicPercentageSizeProperty::PreferredOrMaxSize,
) {
formatting_context::CyclicPercentageIntrinsicContribution::ResolveAsZero => {
- return false;
+ // AD-HOC: The spec resolves a replaced box's cyclic percentage against zero for its min-content
+ // contribution in either axis. But a percentage height with nothing to resolve against is
+ // auto here, as it is everywhere else, for web compatibility — so the box takes its block
+ // size from its aspect ratio or natural size, as with height: auto.
+ if !self.preferred_block_size(node, constraints).is_auto() {
+ return false;
+ }
}
formatting_context::CyclicPercentageIntrinsicContribution::TreatAsInitialValue => {
return !self.block_size_transfers_through_aspect_ratio(node, constraints);
diff --git a/Tests/LibWeb/Crash/Layout/percentage-height-image-without-ratio-in-min-content-measurement.html b/Tests/LibWeb/Crash/Layout/percentage-height-image-without-ratio-in-min-content-measurement.html
new file mode 100644
index 00000000000..7eb9d0609c9
--- /dev/null
+++ b/Tests/LibWeb/Crash/Layout/percentage-height-image-without-ratio-in-min-content-measurement.html
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<!-- The image has no source, so it has no aspect ratio. Its min-content block size is measured for the inner flex
+ container's automatic minimum size, with no containing block height for its percentage height to resolve against. -->
+<div style="display: inline-flex; flex-direction: column">
+ <div style="display: flex; flex-direction: column">
+ <div>
+ <img style="display: block; height: 100%">
+ </div>
+ </div>
+</div>