Skip to content

Commit b2e7858

Browse files
committed
Improve validation of animation-name and will-change properties.
More carefully validate the <ident> type, since the CSS spec gives various restrictions on the identifiers allowed.
1 parent bea0135 commit b2e7858

File tree

3 files changed

+50
-11
lines changed

3 files changed

+50
-11
lines changed

src/css/Properties.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var Properties = {
1818
"animation-duration" : { multi: "<time>", comma: true },
1919
"animation-fill-mode" : { multi: "none | forwards | backwards | both", comma: true },
2020
"animation-iteration-count" : { multi: "<number> | infinite", comma: true },
21-
"animation-name" : { multi: "none | <ident>", comma: true },
21+
"animation-name" : { multi: "none | initial | inherit | unset | <single-animation-name>", comma: true },
2222
"animation-play-state" : { multi: "running | paused", comma: true },
2323
"animation-timing-function" : 1,
2424

@@ -27,29 +27,29 @@ var Properties = {
2727
"-moz-animation-direction" : { multi: "normal | alternate", comma: true },
2828
"-moz-animation-duration" : { multi: "<time>", comma: true },
2929
"-moz-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
30-
"-moz-animation-name" : { multi: "none | <ident>", comma: true },
30+
"-moz-animation-name" : { multi: "none | initial | inherit | unset | <single-animation-name>", comma: true },
3131
"-moz-animation-play-state" : { multi: "running | paused", comma: true },
3232

3333
"-ms-animation-delay" : { multi: "<time>", comma: true },
3434
"-ms-animation-direction" : { multi: "normal | alternate", comma: true },
3535
"-ms-animation-duration" : { multi: "<time>", comma: true },
3636
"-ms-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
37-
"-ms-animation-name" : { multi: "none | <ident>", comma: true },
37+
"-ms-animation-name" : { multi: "none | initial | inherit | unset | <single-animation-name>", comma: true },
3838
"-ms-animation-play-state" : { multi: "running | paused", comma: true },
3939

4040
"-webkit-animation-delay" : { multi: "<time>", comma: true },
4141
"-webkit-animation-direction" : { multi: "normal | alternate", comma: true },
4242
"-webkit-animation-duration" : { multi: "<time>", comma: true },
4343
"-webkit-animation-fill-mode" : { multi: "none | forwards | backwards | both", comma: true },
4444
"-webkit-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
45-
"-webkit-animation-name" : { multi: "none | <ident>", comma: true },
45+
"-webkit-animation-name" : { multi: "none | initial | inherit | unset | <single-animation-name>", comma: true },
4646
"-webkit-animation-play-state" : { multi: "running | paused", comma: true },
4747

4848
"-o-animation-delay" : { multi: "<time>", comma: true },
4949
"-o-animation-direction" : { multi: "normal | alternate", comma: true },
5050
"-o-animation-duration" : { multi: "<time>", comma: true },
5151
"-o-animation-iteration-count" : { multi: "<number> | infinite", comma: true },
52-
"-o-animation-name" : { multi: "none | <ident>", comma: true },
52+
"-o-animation-name" : { multi: "none | initial | inherit | unset | <single-animation-name>", comma: true },
5353
"-o-animation-play-state" : { multi: "running | paused", comma: true },
5454

5555
"appearance" : "icon | window | desktop | workspace | document | tooltip | dialog | button | push-button | hyperlink | radio | radio-button | checkbox | menu-item | tab | menu | menubar | pull-down-menu | pop-up-menu | list-menu | radio-group | checkbox-group | outline-tree | range | field | combo-box | signature | password | normal | none | inherit",
@@ -547,7 +547,7 @@ var Properties = {
547547
"white-space-collapse" : 1,
548548
"widows" : "<integer> | inherit",
549549
"width" : "<length> | <percentage> | <content-sizing> | auto | inherit",
550-
"will-change" : { multi: "<ident>", comma: true },
550+
"will-change" : "<will-change> | inherit | initial | unset",
551551
"word-break" : "normal | keep-all | break-all",
552552
"word-spacing" : "<length> | normal | inherit",
553553
"word-wrap" : "normal | break-word",

src/css/ValidationTypes.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,17 @@ ValidationTypes = {
376376
return part.type === "identifier" || part.wasIdent;
377377
},
378378

379+
"<single-animation-name>": function(part) {
380+
return this["<ident>"](part) &&
381+
/^-?[a-z_][-a-z0-9_]+$/i.test(part) &&
382+
!/^(none|unset|initial|inherit)$/i.test(part);
383+
},
384+
385+
"<animateable-feature-name>": function(part) {
386+
return this["<ident>"](part) &&
387+
!/^(unset|initial|inherit|will-change|auto|scroll-position|contents)$/i.test(part);
388+
},
389+
379390
"<length>": function(part){
380391
if (part.type === "function" && /^(?:\-(?:ms|moz|o|webkit)\-)?calc/i.test(part)){
381392
return true;
@@ -502,6 +513,10 @@ ValidationTypes = {
502513
complex: {
503514
__proto__: null,
504515

516+
"<animateable-feature>":
517+
// scroll-position | contents | <custom-ident>
518+
Matcher.cast("scroll-position | contents | <animateable-feature-name>"),
519+
505520
"<bg-position>": Matcher.cast("<position>").hash(),
506521

507522
"<bg-size>":
@@ -571,6 +586,10 @@ ValidationTypes = {
571586

572587
"<text-decoration>":
573588
// none | [ underline || overline || line-through || blink ] | inherit
574-
Matcher.oror("underline", "overline", "line-through", "blink")
589+
Matcher.oror("underline", "overline", "line-through", "blink"),
590+
591+
"<will-change>":
592+
// auto | <animateable-feature>#
593+
Matcher.alt("auto", Matcher.cast("<animateable-feature>").hash())
575594
}
576595
};

tests/css/Validation.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,29 @@
101101
valid: [
102102
"none",
103103
"foo",
104+
"red",
105+
"-red",
106+
"-specific",
107+
"sliding-vertically",
108+
"test1",
109+
"test1, animation4",
104110
"foo, bar",
105111
"none, none",
106112
"none, foo",
107-
"has_underscore"
113+
"has_underscore",
114+
"none, -moz-specific, sliding",
115+
"initial",
116+
"inherit",
117+
"unset"
108118
],
109119

110120
invalid: {
111-
"1px" : "Expected (none | <ident>) but found '1px'."
121+
"1px" : "Expected (none | initial | inherit | unset | <single-animation-name>) but found '1px'.",
122+
"--invalid" : "Expected (none | initial | inherit | unset | <single-animation-name>) but found '--invalid'."
123+
},
124+
125+
error: {
126+
"-0num": "Unexpected token '0num' at line 1, col 24."
112127
}
113128
}));
114129

@@ -1241,18 +1256,23 @@
12411256
property: "will-change",
12421257

12431258
valid: [
1259+
"inherit",
1260+
"initial",
1261+
"unset",
12441262
"auto",
12451263
"scroll-position",
12461264
"contents",
12471265
"opacity",
12481266
"transform",
12491267
"opacity, transform",
1268+
"left, top",
12501269
"height, opacity, transform, width"
12511270
],
12521271

12531272
invalid: {
1254-
"2px" : "Expected (<ident>) but found '2px'.",
1255-
"opacity transform" : "Expected end of value but found 'transform'."
1273+
"2px" : "Expected (<will-change> | inherit | initial | unset) but found '2px'.",
1274+
"opacity transform" : "Expected end of value but found 'transform'.",
1275+
"will-change" : "Expected (<will-change> | inherit | initial | unset) but found 'will-change'."
12561276
}
12571277
}));
12581278

0 commit comments

Comments
 (0)