LibWeb: Treat media query with an invalid media type as invalid

This commit is contained in:
Tim Ledbetter 2025-03-09 16:22:40 +00:00 committed by Sam Atkins
commit bf15b7ac12
Notes: github-actions[bot] 2025-03-09 17:49:36 +00:00
2 changed files with 35 additions and 0 deletions

View file

@ -112,6 +112,10 @@ NonnullRefPtr<MediaQuery> Parser::parse_media_query(TokenStream<ComponentValue>&
// `<media-type>`
if (auto media_type = parse_media_type(tokens); media_type.has_value()) {
// https://drafts.csswg.org/mediaqueries-4/#error-handling
// An unknown <media-type> must be treated as not matching.
if (media_type.value() == MediaQuery::MediaType::Unknown)
return invalid_media_query();
media_query->m_media_type = media_type.value();
tokens.discard_whitespace();
} else {

View file

@ -0,0 +1,31 @@
<!doctype html>
<html>
<head>
<title>Test: syntax error handling in Media Queries</title>
<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
<link rel="help" href="https://drafts.csswg.org/mediaqueries4/#error-handling">
<link rel="match" href="../../../../expected/wpt-import/css/reference/ref-filled-green-100px-square.xht">
<meta name="assert" content="'and' is an invalid media type">
<meta name="flags" content="invalid">
<style>
div {
width: 100px;
height: 100px;
}
@media all {
div { background-color: green; }
}
@media not and {
div { background-color: red; }
}
@media and {
div { background-color: red; }
}
</style>
</head>
<body>
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div></div>
</body>
</html>