mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-05 15:49:11 +00:00
LibWeb: Check for missing node or invalid query in obtain_theme_color
This commit is contained in:
parent
6fd03425b2
commit
9f2ce259ad
Notes:
github-actions[bot]
2025-01-12 19:48:07 +00:00
Author: https://github.com/Gingeh
Commit: 9f2ce259ad
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3207
Reviewed-by: https://github.com/tcl3 ✅
3 changed files with 11 additions and 2 deletions
|
@ -1501,7 +1501,7 @@ void Document::obtain_theme_color()
|
||||||
auto media = element.attribute(HTML::AttributeNames::media);
|
auto media = element.attribute(HTML::AttributeNames::media);
|
||||||
if (media.has_value()) {
|
if (media.has_value()) {
|
||||||
auto query = parse_media_query(context, media.value());
|
auto query = parse_media_query(context, media.value());
|
||||||
if (window() && !query->evaluate(*window()))
|
if (query.is_null() || !window() || !query->evaluate(*window()))
|
||||||
return TraversalDecision::Continue;
|
return TraversalDecision::Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1514,7 +1514,7 @@ void Document::obtain_theme_color()
|
||||||
// 4. If color is not failure, then return color.
|
// 4. If color is not failure, then return color.
|
||||||
if (!css_value.is_null() && css_value->is_color()) {
|
if (!css_value.is_null() && css_value->is_color()) {
|
||||||
Optional<Layout::NodeWithStyle const&> root_node;
|
Optional<Layout::NodeWithStyle const&> root_node;
|
||||||
if (html_element())
|
if (html_element() && html_element()->layout_node())
|
||||||
root_node = *html_element()->layout_node();
|
root_node = *html_element()->layout_node();
|
||||||
|
|
||||||
theme_color = css_value->to_color(root_node);
|
theme_color = css_value->to_color(root_node);
|
||||||
|
|
1
Tests/LibWeb/Text/expected/theme-color-crash.txt
Normal file
1
Tests/LibWeb/Text/expected/theme-color-crash.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
PASS (didn't crash)
|
8
Tests/LibWeb/Text/input/theme-color-crash.html
Normal file
8
Tests/LibWeb/Text/input/theme-color-crash.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<meta name="theme-color" content="red">
|
||||||
|
<script src="include.js"></script>
|
||||||
|
<script>
|
||||||
|
test(() => {
|
||||||
|
println("PASS (didn't crash)");
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue