Skip to content

Commit

Permalink
setting selectorText fails when passed a selector that includes names…
Browse files Browse the repository at this point in the history
…pace prefixes

https://bugs.webkit.org/show_bug.cgi?id=247830
rdar://problem/102260326

Reviewed by Tim Nguyen.

* LayoutTests/imported/w3c/web-platform-tests/css/cssom/CSSStyleRule-set-selectorText-namespace-expected.txt:
Expect PASS.

* Source/WebCore/css/CSSPageRule.cpp:
(WebCore::CSSPageRule::setSelectorText): Pass the style sheet in.
* Source/WebCore/css/CSSStyleRule.cpp:
(WebCore::CSSStyleRule::setSelectorText): Ditto.
* Source/WebCore/css/parser/CSSParser.cpp:
(WebCore::CSSParser::parseSelector): Pass the style sheet along.
* Source/WebCore/css/parser/CSSParser.h: Take an optional style sheet.

Canonical link: https://commits.webkit.org/256599@main
  • Loading branch information
darinadler committed Nov 12, 2022
1 parent 81e1905 commit da821c3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
@@ -1,8 +1,8 @@
SVG text

FAIL CSSStyleRule: selectorText value: |.style1| isMatch: false assert_equals: expected "rgb(255, 0, 255)" but got "rgb(0, 0, 255)"
FAIL CSSStyleRule: selectorText value: |svg|*.style1 | isMatch: true assert_equals: expected "svg|*.style0" but got ".style1"
FAIL CSSStyleRule: selectorText value: |*|*.style1 | isMatch: true assert_equals: expected "svg|*.style0" but got ".style1"
FAIL CSSStyleRule: selectorText value: | *.style1 | isMatch: false assert_equals: expected "svg|*.style0" but got ".style1"
FAIL CSSStyleRule: selectorText value: |p| isMatch: false assert_equals: expected "svg|*.style0" but got ".style1"
PASS CSSStyleRule: selectorText value: |.style1| isMatch: false
PASS CSSStyleRule: selectorText value: |svg|*.style1 | isMatch: true
PASS CSSStyleRule: selectorText value: |*|*.style1 | isMatch: true
PASS CSSStyleRule: selectorText value: | *.style1 | isMatch: false
PASS CSSStyleRule: selectorText value: |p| isMatch: false

3 changes: 2 additions & 1 deletion Source/WebCore/css/CSSPageRule.cpp
Expand Up @@ -65,7 +65,8 @@ String CSSPageRule::selectorText() const
void CSSPageRule::setSelectorText(const String& selectorText)
{
CSSParser parser(parserContext());
auto selectorList = parser.parseSelector(selectorText);
auto* sheet = parentStyleSheet();
auto selectorList = parser.parseSelector(selectorText, sheet ? &sheet->contents() : nullptr);
if (!selectorList)
return;

Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/css/CSSStyleRule.cpp
Expand Up @@ -98,7 +98,8 @@ void CSSStyleRule::setSelectorText(const String& selectorText)
return;

CSSParser p(parserContext());
auto selectorList = p.parseSelector(selectorText);
auto* sheet = parentStyleSheet();
auto selectorList = p.parseSelector(selectorText, sheet ? &sheet->contents() : nullptr);
if (!selectorList)
return;

Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/css/parser/CSSParser.cpp
Expand Up @@ -169,9 +169,9 @@ CSSParser::ParseResult CSSParser::parseValue(MutableStyleProperties& declaration
return CSSParserImpl::parseValue(&declaration, propertyID, string, important, m_context);
}

std::optional<CSSSelectorList> CSSParser::parseSelector(const String& string)
std::optional<CSSSelectorList> CSSParser::parseSelector(const String& string, StyleSheetContents* styleSheet)
{
return parseCSSSelector(CSSTokenizer(string).tokenRange(), m_context, nullptr);
return parseCSSSelector(CSSTokenizer(string).tokenRange(), m_context, styleSheet);
}

Ref<ImmutableStyleProperties> CSSParser::parseInlineStyleDeclaration(const String& string, const Element* element)
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/css/parser/CSSParser.h
Expand Up @@ -83,7 +83,7 @@ class CSSParser {
WEBCORE_EXPORT bool parseDeclaration(MutableStyleProperties&, const String&);
static Ref<ImmutableStyleProperties> parseInlineStyleDeclaration(const String&, const Element*);

std::optional<CSSSelectorList> parseSelector(const String&);
std::optional<CSSSelectorList> parseSelector(const String&, StyleSheetContents* = nullptr);

RefPtr<CSSValue> parseValueWithVariableReferences(CSSPropertyID, const CSSValue&, Style::BuilderState&);

Expand Down

0 comments on commit da821c3

Please sign in to comment.