diff --git a/Tests/LibWeb/Text/expected/css/media-query-serialization-basic.txt b/Tests/LibWeb/Text/expected/css/media-query-serialization-basic.txt index d7e81b9b6b4..a36ee22bd83 100644 --- a/Tests/LibWeb/Text/expected/css/media-query-serialization-basic.txt +++ b/Tests/LibWeb/Text/expected/css/media-query-serialization-basic.txt @@ -1,15 +1,10 @@ @media screen { - } @media screen and ((min-width: 20px) and (max-width: 40px)) { - } @media screen and (min-resolution: 1dppx) { - } @media screen and (min-resolution: 2dppx) { - } @media screen and (min-resolution: 2.54dppx) { - } diff --git a/Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp b/Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp index 5d82779c846..134339ebf59 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSMediaRule.cpp @@ -54,6 +54,11 @@ String CSSMediaRule::serialized() const builder.append(condition_text()); // 3. A single SPACE (U+0020), followed by the string "{", i.e., LEFT CURLY BRACKET (U+007B), followed by a newline. builder.append(" {\n"sv); + // AD-HOC: All modern browsers omit the ending newline if there are no CSS rules, so let's do the same. + if (css_rules().length() == 0) { + builder.append('}'); + return MUST(builder.to_string()); + } // 4. The result of performing serialize a CSS rule on each rule in the rule’s cssRules list, separated by a newline and indented by two spaces. for (size_t i = 0; i < css_rules().length(); i++) { auto rule = css_rules().item(i);