mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-22 16:09:23 +00:00
LibWeb: Avoid crash evaluating media query in document lacking window
In some cases a document may lack an associated window - to fix this for now we just return false but perhaps there are some media queries we should still attempt to resolve.
This commit is contained in:
parent
7ee8645b9c
commit
b1801c0bc9
Notes:
github-actions[bot]
2025-10-17 16:27:27 +00:00
Author: https://github.com/Calme1709
Commit: b1801c0bc9
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6452
Reviewed-by: https://github.com/AtkinsSJ
2 changed files with 12 additions and 1 deletions
|
@ -99,7 +99,12 @@ String MediaFeature::to_string() const
|
||||||
MatchResult MediaFeature::evaluate(DOM::Document const* document) const
|
MatchResult MediaFeature::evaluate(DOM::Document const* document) const
|
||||||
{
|
{
|
||||||
VERIFY(document);
|
VERIFY(document);
|
||||||
VERIFY(document->window());
|
|
||||||
|
// FIXME: In some cases (e.g. when parsing HTML using DOMParser::parse_from_string()) a document may not be associated with a window -
|
||||||
|
// for now we just return false but perhaps there are some media queries we should still attempt to resolve.
|
||||||
|
if (!document->window())
|
||||||
|
return MatchResult::False;
|
||||||
|
|
||||||
auto maybe_queried_value = document->window()->query_media_feature(m_id);
|
auto maybe_queried_value = document->window()->query_media_feature(m_id);
|
||||||
if (!maybe_queried_value.has_value())
|
if (!maybe_queried_value.has_value())
|
||||||
return MatchResult::False;
|
return MatchResult::False;
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<script>
|
||||||
|
const dom = new DOMParser().parseFromString(`<style media="width < 50px">`, "text/html");
|
||||||
|
</script>
|
||||||
|
</html>
|
Loading…
Add table
Add a link
Reference in a new issue