Skip to content

Commit 31ae975

Browse files
committed
[CSS] Invalid @Property rule should be ignored at parse-time
https://bugs.webkit.org/show_bug.cgi?id=263007 rdar://116803886 Reviewed by Antti Koivisto and Tim Nguyen. This patch moves most of the validity checks from rule-registration-time (during rule set building) to parse-time, thus preventing invalid @Property rules to appear in the CSSOM. * LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-cssom-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-cssom.html: * LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-expected.txt: * LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property.html: * Source/WebCore/css/parser/CSSParserImpl.cpp: (WebCore::CSSParserImpl::consumePropertyRule): * Source/WebCore/style/CustomPropertyRegistry.cpp: (WebCore::Style::CustomPropertyRegistry::registerFromStylesheet): Canonical link: https://commits.webkit.org/269466@main
1 parent 9e25f51 commit 31ae975

File tree

6 files changed

+226
-122
lines changed

6 files changed

+226
-122
lines changed
Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,41 @@
11

2+
PASS Rule for --no-descriptors is invalid
3+
PASS Rule for --no-syntax is invalid
4+
PASS Rule for --no-inherits is invalid
5+
PASS Rule for --no-initial-color-value is invalid
6+
PASS Rule for --syntax-only is invalid
7+
PASS Rule for --inherits-only is invalid
8+
PASS Rule for --initial-value-only is invalid
29
PASS Rule for --valid has expected cssText
310
PASS Rule for --valid-reverse has expected cssText
411
PASS Rule for --valid-universal has expected cssText
512
PASS Rule for --valid-whitespace has expected cssText
613
PASS Rule for --vALId has expected cssText
7-
PASS Rule for --no-descriptors has expected cssText
8-
PASS Rule for --no-syntax has expected cssText
9-
PASS Rule for --no-inherits has expected cssText
10-
PASS Rule for --no-initial-value has expected cssText
11-
PASS Rule for --syntax-only has expected cssText
12-
PASS Rule for --inherits-only has expected cssText
13-
PASS Rule for --initial-value-only has expected cssText
14+
PASS Rule for --no-initial-universal-value has expected cssText
1415
PASS Rule for --tab tab has expected cssText
1516
PASS CSSRule.type returns 0
1617
PASS Rule for --valid returns expected value for CSSPropertyRule.name
1718
PASS Rule for --valid-reverse returns expected value for CSSPropertyRule.name
1819
PASS Rule for --valid-universal returns expected value for CSSPropertyRule.name
1920
PASS Rule for --valid-whitespace returns expected value for CSSPropertyRule.name
2021
PASS Rule for --vALId returns expected value for CSSPropertyRule.name
21-
PASS Rule for --no-descriptors returns expected value for CSSPropertyRule.name
22-
PASS Rule for --no-syntax returns expected value for CSSPropertyRule.name
23-
PASS Rule for --no-inherits returns expected value for CSSPropertyRule.name
24-
PASS Rule for --no-initial-value returns expected value for CSSPropertyRule.name
25-
PASS Rule for --syntax-only returns expected value for CSSPropertyRule.name
26-
PASS Rule for --inherits-only returns expected value for CSSPropertyRule.name
27-
PASS Rule for --initial-value-only returns expected value for CSSPropertyRule.name
22+
PASS Rule for --no-initial-universal-value returns expected value for CSSPropertyRule.name
2823
PASS Rule for --valid returns expected value for CSSPropertyRule.syntax
2924
PASS Rule for --valid-reverse returns expected value for CSSPropertyRule.syntax
3025
PASS Rule for --valid-universal returns expected value for CSSPropertyRule.syntax
3126
PASS Rule for --valid-whitespace returns expected value for CSSPropertyRule.syntax
3227
PASS Rule for --vALId returns expected value for CSSPropertyRule.syntax
33-
PASS Rule for --no-descriptors returns expected value for CSSPropertyRule.syntax
34-
PASS Rule for --no-syntax returns expected value for CSSPropertyRule.syntax
35-
PASS Rule for --no-inherits returns expected value for CSSPropertyRule.syntax
36-
PASS Rule for --no-initial-value returns expected value for CSSPropertyRule.syntax
37-
PASS Rule for --syntax-only returns expected value for CSSPropertyRule.syntax
38-
PASS Rule for --inherits-only returns expected value for CSSPropertyRule.syntax
39-
PASS Rule for --initial-value-only returns expected value for CSSPropertyRule.syntax
28+
PASS Rule for --no-initial-universal-value returns expected value for CSSPropertyRule.syntax
4029
PASS Rule for --valid returns expected value for CSSPropertyRule.inherits
4130
PASS Rule for --valid-reverse returns expected value for CSSPropertyRule.inherits
4231
PASS Rule for --valid-universal returns expected value for CSSPropertyRule.inherits
4332
PASS Rule for --valid-whitespace returns expected value for CSSPropertyRule.inherits
4433
PASS Rule for --vALId returns expected value for CSSPropertyRule.inherits
45-
PASS Rule for --no-descriptors returns expected value for CSSPropertyRule.inherits
46-
PASS Rule for --no-syntax returns expected value for CSSPropertyRule.inherits
47-
PASS Rule for --no-inherits returns expected value for CSSPropertyRule.inherits
48-
PASS Rule for --no-initial-value returns expected value for CSSPropertyRule.inherits
49-
PASS Rule for --syntax-only returns expected value for CSSPropertyRule.inherits
50-
PASS Rule for --inherits-only returns expected value for CSSPropertyRule.inherits
51-
PASS Rule for --initial-value-only returns expected value for CSSPropertyRule.inherits
34+
PASS Rule for --no-initial-universal-value returns expected value for CSSPropertyRule.inherits
5235
PASS Rule for --valid returns expected value for CSSPropertyRule.initialValue
5336
PASS Rule for --valid-reverse returns expected value for CSSPropertyRule.initialValue
5437
PASS Rule for --valid-universal returns expected value for CSSPropertyRule.initialValue
5538
PASS Rule for --valid-whitespace returns expected value for CSSPropertyRule.initialValue
5639
PASS Rule for --vALId returns expected value for CSSPropertyRule.initialValue
57-
PASS Rule for --no-descriptors returns expected value for CSSPropertyRule.initialValue
58-
PASS Rule for --no-syntax returns expected value for CSSPropertyRule.initialValue
59-
PASS Rule for --no-inherits returns expected value for CSSPropertyRule.initialValue
60-
PASS Rule for --no-initial-value returns expected value for CSSPropertyRule.initialValue
61-
PASS Rule for --syntax-only returns expected value for CSSPropertyRule.initialValue
62-
PASS Rule for --inherits-only returns expected value for CSSPropertyRule.initialValue
63-
PASS Rule for --initial-value-only returns expected value for CSSPropertyRule.initialValue
40+
PASS Rule for --no-initial-universal-value returns expected value for CSSPropertyRule.initialValue
6441

LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-cssom.html

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
inherits: false;
1919
}
2020
@property --valid-whitespace {
21-
syntax: " <color>+ ";
21+
syntax: " <color># ";
2222
inherits: false;
2323
initial-value: red, blue;
2424
}
@@ -38,10 +38,14 @@
3838
syntax: "<color> | none";
3939
initial-value: red;
4040
}
41-
@property --no-initial-value {
41+
@property --no-initial-color-value {
4242
syntax: "<color> | none";
4343
inherits: false;
4444
}
45+
@property --no-initial-universal-value {
46+
syntax: "*";
47+
inherits: false;
48+
}
4549
@property --syntax-only {
4650
syntax: "<color> | none";
4751
}
@@ -52,7 +56,10 @@
5256
initial-value: red;
5357
}
5458
/* U+0009 CHARACTER TABULATION */
55-
@property --tab\9 tab { }
59+
@property --tab\9 tab {
60+
syntax: "*";
61+
inherits: true;
62+
}
5663
</style>
5764
<script>
5865

@@ -66,6 +73,13 @@
6673
return null;
6774
}
6875

76+
function test_invalid(name) {
77+
test(() => {
78+
let rule = find_at_property_rule(name);
79+
assert_true(!rule);
80+
}, `Rule for ${name} is invalid`);
81+
}
82+
6983
function test_css_text(name, expected) {
7084
test(() => {
7185
let rule = find_at_property_rule(name);
@@ -106,22 +120,26 @@
106120
}, `Rule for ${name} returns expected value for CSSPropertyRule.initialValue`);
107121
}
108122

123+
// Invalid @property rules.
124+
test_invalid('--no-descriptors');
125+
test_invalid('--no-syntax');
126+
test_invalid('--no-inherits');
127+
test_invalid('--no-initial-color-value');
128+
test_invalid('--syntax-only', '@property --syntax-only { syntax: "<color> | none"; }');
129+
test_invalid('--inherits-only', '@property --inherits-only { inherits: true; }');
130+
test_invalid('--initial-value-only', '@property --initial-value-only { initial-value: red; }');
131+
109132
// CSSPropertyRule.cssText
110133

111134
test_css_text('--valid', '@property --valid { syntax: "<color> | none"; inherits: false; initial-value: red; }');
112135
test_css_text('--valid-reverse', '@property --valid-reverse { syntax: "<length>"; inherits: true; initial-value: 0px; }');
113136
test_css_text('--valid-universal', '@property --valid-universal { syntax: "*"; inherits: false; }');
114-
test_css_text('--valid-whitespace', '@property --valid-whitespace { syntax: " <color>+ "; inherits: false; initial-value: red, blue; }');
137+
test_css_text('--valid-whitespace', '@property --valid-whitespace { syntax: " <color># "; inherits: false; initial-value: red, blue; }');
115138
test_css_text('--vALId', '@property --vALId { syntax: "<color> | none"; inherits: false; initial-value: red; }');
116139

117-
test_css_text('--no-descriptors', '@property --no-descriptors { }');
118-
test_css_text('--no-syntax', '@property --no-syntax { inherits: false; initial-value: red; }');
119-
test_css_text('--no-inherits', '@property --no-inherits { syntax: "<color> | none"; initial-value: red; }');
120-
test_css_text('--no-initial-value', '@property --no-initial-value { syntax: "<color> | none"; inherits: false; }');
121-
test_css_text('--syntax-only', '@property --syntax-only { syntax: "<color> | none"; }');
122-
test_css_text('--inherits-only', '@property --inherits-only { inherits: true; }');
123-
test_css_text('--initial-value-only', '@property --initial-value-only { initial-value: red; }');
124-
test_css_text('--tab\ttab', '@property --tab\\9 tab { }');
140+
test_css_text('--no-initial-universal-value', '@property --no-initial-universal-value { syntax: "*"; inherits: false; }');
141+
142+
test_css_text('--tab\ttab', '@property --tab\\9 tab { syntax: "*"; inherits: true; }');
125143

126144
// CSSRule.type
127145

@@ -138,29 +156,17 @@
138156
test_name('--valid-whitespace');
139157
test_name('--vALId');
140158

141-
test_name('--no-descriptors');
142-
test_name('--no-syntax');
143-
test_name('--no-inherits');
144-
test_name('--no-initial-value');
145-
test_name('--syntax-only');
146-
test_name('--inherits-only');
147-
test_name('--initial-value-only');
159+
test_name('--no-initial-universal-value');
148160

149161
// CSSPropertyRule.syntax
150162

151163
test_syntax('--valid', '<color> | none');
152164
test_syntax('--valid-reverse', '<length>');
153165
test_syntax('--valid-universal', '*');
154-
test_syntax('--valid-whitespace', ' <color>+ ');
166+
test_syntax('--valid-whitespace', ' <color># ');
155167
test_syntax('--vALId', '<color> | none');
156168

157-
test_syntax('--no-descriptors', '');
158-
test_syntax('--no-syntax', '');
159-
test_syntax('--no-inherits', '<color> | none');
160-
test_syntax('--no-initial-value', '<color> | none');
161-
test_syntax('--syntax-only', '<color> | none');
162-
test_syntax('--inherits-only', '');
163-
test_syntax('--initial-value-only', '');
169+
test_syntax('--no-initial-universal-value', '*');
164170

165171
// CSSPropertyRule.inherits
166172

@@ -170,13 +176,7 @@
170176
test_inherits('--valid-whitespace', false);
171177
test_inherits('--vALId', false);
172178

173-
test_inherits('--no-descriptors', false);
174-
test_inherits('--no-syntax', false);
175-
test_inherits('--no-inherits', false);
176-
test_inherits('--no-initial-value', false);
177-
test_inherits('--syntax-only', false);
178-
test_inherits('--inherits-only', true);
179-
test_inherits('--initial-value-only', false);
179+
test_inherits('--no-initial-universal-value', false);
180180

181181
// CSSPropertyRule.initialValue
182182

@@ -186,12 +186,6 @@
186186
test_initial_value('--valid-whitespace', 'red, blue');
187187
test_initial_value('--vALId', 'red');
188188

189-
test_initial_value('--no-descriptors', null);
190-
test_initial_value('--no-syntax', 'red');
191-
test_initial_value('--no-inherits', 'red');
192-
test_initial_value('--no-initial-value', null);
193-
test_initial_value('--syntax-only', null);
194-
test_initial_value('--inherits-only', null);
195-
test_initial_value('--initial-value-only', 'red');
189+
test_initial_value('--no-initial-universal-value', null);
196190

197191
</script>

LayoutTests/imported/w3c/web-platform-tests/css/css-properties-values-api/at-property-expected.txt

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,49 @@
22
PASS Attribute 'syntax' returns expected value for ["<color>"]
33
PASS Attribute 'syntax' returns expected value for ["<color> | none"]
44
PASS Attribute 'syntax' returns expected value for ["<color># | <image> | none"]
5+
PASS Attribute 'syntax' returns expected value for ["foo | <length>#"]
56
PASS Attribute 'syntax' returns expected value for ["foo | bar | baz"]
6-
PASS Attribute 'syntax' returns expected value for ["*"]
77
PASS Attribute 'syntax' returns expected value for ["notasyntax"]
8-
PASS Attribute 'syntax' returns expected value for [red]
9-
PASS Attribute 'syntax' returns expected value for [rgb(255, 0, 0)]
10-
PASS Attribute 'syntax' returns expected value for [<color>]
11-
PASS Attribute 'syntax' returns expected value for [foo | bar]
8+
PASS Attribute 'syntax' returns expected value for ["*"]
9+
PASS Attribute 'syntax' returns expected value for [" * "]
10+
PASS Attribute 'syntax' returns expected value for ["* "]
11+
PASS Attribute 'syntax' returns expected value for [" * "]
12+
PASS Attribute 'syntax' returns expected value for ["red"]
13+
PASS Attribute 'syntax' makes the @property rule invalid for ["rgb(255, 0, 0)"]
14+
PASS Attribute 'syntax' makes the @property rule invalid for [<color>]
15+
PASS Attribute 'syntax' makes the @property rule invalid for [foo | bar]
16+
PASS Attribute 'syntax' makes the @property rule invalid for ["default"]
17+
PASS Attribute 'syntax' makes the @property rule invalid for ["Default"]
18+
PASS Attribute 'syntax' makes the @property rule invalid for ["initial"]
19+
PASS Attribute 'syntax' makes the @property rule invalid for ["Initial"]
20+
PASS Attribute 'syntax' makes the @property rule invalid for ["inherit"]
21+
PASS Attribute 'syntax' makes the @property rule invalid for ["Inherit"]
22+
PASS Attribute 'syntax' makes the @property rule invalid for ["unset"]
23+
PASS Attribute 'syntax' makes the @property rule invalid for ["Unset"]
24+
PASS Attribute 'syntax' makes the @property rule invalid for ["revert"]
25+
PASS Attribute 'syntax' makes the @property rule invalid for ["Revert"]
26+
PASS Attribute 'syntax' makes the @property rule invalid for ["revert-layer"]
27+
PASS Attribute 'syntax' makes the @property rule invalid for ["Revert-layer"]
28+
PASS Attribute 'syntax' makes the @property rule invalid for ["foo bar"]
29+
PASS Attribute 'syntax' makes the @property rule invalid for ["Foo <length>"]
30+
PASS Attribute 'syntax' makes the @property rule invalid for ["foo, bar"]
31+
PASS Attribute 'syntax' makes the @property rule invalid for ["<length> <percentage>"]
32+
PASS Attribute 'syntax' makes the @property rule invalid for ["|<length>"]
1233
PASS Attribute 'initial-value' returns expected value for [10px]
1334
PASS Attribute 'initial-value' returns expected value for [rgb(1, 2, 3)]
1435
PASS Attribute 'initial-value' returns expected value for [red]
1536
PASS Attribute 'initial-value' returns expected value for [foo]
1637
PASS Attribute 'initial-value' returns expected value for [if(){}]
17-
PASS Attribute 'initial-value' returns expected value for [var(--x)]
38+
PASS Attribute 'initial-value' makes the @property rule invalid for [3em]
39+
FAIL Attribute 'initial-value' makes the @property rule invalid for [var(--x)] assert_true: expected true got false
1840
PASS Attribute 'inherits' returns expected value for [true]
1941
PASS Attribute 'inherits' returns expected value for [false]
20-
PASS Attribute 'inherits' returns expected value for [none]
21-
PASS Attribute 'inherits' returns expected value for [0]
22-
PASS Attribute 'inherits' returns expected value for [1]
23-
PASS Attribute 'inherits' returns expected value for ["true"]
24-
PASS Attribute 'inherits' returns expected value for ["false"]
25-
PASS Attribute 'inherits' returns expected value for [calc(0)]
42+
PASS Attribute 'inherits' makes the @property rule invalid for [none]
43+
PASS Attribute 'inherits' makes the @property rule invalid for [0]
44+
PASS Attribute 'inherits' makes the @property rule invalid for [1]
45+
PASS Attribute 'inherits' makes the @property rule invalid for ["true"]
46+
PASS Attribute 'inherits' makes the @property rule invalid for ["false"]
47+
PASS Attribute 'inherits' makes the @property rule invalid for [calc(0)]
2648
PASS Invalid property name does not parse [foo]
2749
PASS Invalid property name does not parse [-foo]
2850
PASS Rule applied [*, if(){}, false]

0 commit comments

Comments
 (0)