Skip to content

Commit 9aa1b79

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 889093c commit 9aa1b79

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",
@@ -557,7 +557,7 @@ var Properties = {
557557
"white-space-collapse" : 1,
558558
"widows" : "<integer> | inherit",
559559
"width" : "<length> | <percentage> | <content-sizing> | auto | inherit",
560-
"will-change" : { multi: "<ident>", comma: true },
560+
"will-change" : "<will-change> | inherit | initial | unset",
561561
"word-break" : "normal | keep-all | break-all",
562562
"word-spacing" : "<length> | normal | inherit",
563563
"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;
@@ -534,6 +545,10 @@ ValidationTypes = {
534545
complex: {
535546
__proto__: null,
536547

548+
"<animateable-feature>":
549+
// scroll-position | contents | <custom-ident>
550+
Matcher.cast("scroll-position | contents | <animateable-feature-name>"),
551+
537552
"<bg-position>": Matcher.cast("<position>").hash(),
538553

539554
"<bg-size>":
@@ -624,6 +639,10 @@ ValidationTypes = {
624639

625640
"<text-decoration>":
626641
// none | [ underline || overline || line-through || blink ] | inherit
627-
Matcher.oror("underline", "overline", "line-through", "blink")
642+
Matcher.oror("underline", "overline", "line-through", "blink"),
643+
644+
"<will-change>":
645+
// auto | <animateable-feature>#
646+
Matcher.alt("auto", Matcher.cast("<animateable-feature>").hash())
628647
}
629648
};

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

@@ -1357,18 +1372,23 @@
13571372
property: "will-change",
13581373

13591374
valid: [
1375+
"inherit",
1376+
"initial",
1377+
"unset",
13601378
"auto",
13611379
"scroll-position",
13621380
"contents",
13631381
"opacity",
13641382
"transform",
13651383
"opacity, transform",
1384+
"left, top",
13661385
"height, opacity, transform, width"
13671386
],
13681387

13691388
invalid: {
1370-
"2px" : "Expected (<ident>) but found '2px'.",
1371-
"opacity transform" : "Expected end of value but found 'transform'."
1389+
"2px" : "Expected (<will-change> | inherit | initial | unset) but found '2px'.",
1390+
"opacity transform" : "Expected end of value but found 'transform'.",
1391+
"will-change" : "Expected (<will-change> | inherit | initial | unset) but found 'will-change'."
13721392
}
13731393
}));
13741394

0 commit comments

Comments
 (0)