Skip to content
Permalink
Browse files
Do not consider title from non-css stylesheet for preferred set
https://bugs.webkit.org/show_bug.cgi?id=118012

Reviewed by Antti Koivisto.

Merge https://chromium.googlesource.com/chromium/blink/+/ac653f351a222c4ee80ddd656aaaf06c07d87125

Do not consider title from non-css stylesheet for preferred set.

Title on a style element can be used to select the preferred stylesheet set.
If the type attribute of the style element is not text/css, the title should
never be set as the key for the preferred stylesheet set.

* LayoutTests/fast/css/style-preferred-stylesheet-01-expected.html: Added.
* LayoutTests/fast/css/style-preferred-stylesheet-01.html: Added.
* LayoutTests/fast/css/style-preferred-stylesheet-02-expected.html: Added.
* LayoutTests/fast/css/style-preferred-stylesheet-02.html: Added.
* Source/WebCore/style/StyleScope.cpp:
(WebCore::Style::Scope::collectActiveStyleSheets):

Canonical link: https://commits.webkit.org/253632@main
  • Loading branch information
rniwa committed Aug 21, 2022
1 parent 2f1268f commit 4e99fbf6f75a837e65d1cd7087cbb7ba9522fc63
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 1 deletion.
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<p>This text should not be red.</p>
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<!-- title of a style element with invalid type should never be the preferred stylesheet set -->
<style type="text/invalid" title="preferred"></style>
<link rel="alternate stylesheet" type="text/css" title="preferred" href="data:text/css,p{color:red}">
<p>This text should not be red.</p>
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<p style="color:green">This text should be green.</p>
@@ -0,0 +1,5 @@
<!DOCTYPE html>
<!-- title of a style element define the preferred stylesheet set -->
<style type="text/css" title="preferred"></style>
<link rel="alternate stylesheet" type="text/css" title="preferred" href="data:text/css,p{color:green}">
<p>This text should be green.</p>
@@ -395,7 +395,7 @@ auto Scope::collectActiveStyleSheets() -> ActiveStyleSheetCollection
// (thus making it PREFERRED or ALTERNATE rather than
// PERSISTENT).
auto& rel = element.attributeWithoutSynchronization(relAttr);
if (!enabledViaScript && !title.isEmpty()) {
if (!enabledViaScript && sheet && !title.isEmpty()) {
// Yes, we have a title.
if (m_preferredStylesheetSetName.isEmpty()) {
// No preferred set has been established. If

0 comments on commit 4e99fbf

Please sign in to comment.