Skip to content

Commit 0afb9a8

Browse files
Onno van der Zeecscott
authored andcommitted
Precisely validate <filter-function-list>.
See: https://drafts.fxtf.org/filters/#FilterProperty Fixes: #161
1 parent 6ea6269 commit 0afb9a8

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

src/css/Properties.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ var Properties = {
285285
"empty-cells" : "show | hide | inherit",
286286

287287
//F
288-
"filter" : 1,
289288
"fill" : "<color> | inherit",
289+
"filter" : "<filter-function-list> | none",
290290
"fit" : "fill | hidden | meet | slice",
291291
"fit-position" : 1,
292292
"flex" : "<flex>",

src/css/ValidationTypes.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,21 @@ var ValidationTypes = {
232232

233233
"<feature-tag-value>": function(part){
234234
return (part.type === "function" && /^[A-Z0-9]{4}$/i.test(part));
235+
},
236+
237+
"<filter-function>": function(part){
238+
return part.type === "function" && (
239+
part.name === 'blur' ||
240+
part.name === 'brightness' ||
241+
part.name === 'contrast' ||
242+
part.name === 'custom' || // Not actually in formal spec.
243+
part.name === 'drop-shadow' ||
244+
part.name === 'grayscale' ||
245+
part.name === 'hue-rotate' ||
246+
part.name === 'invert' ||
247+
part.name === 'opacity' ||
248+
part.name === 'saturate' ||
249+
part.name === 'sepia');
235250
}
236251
},
237252

@@ -340,6 +355,24 @@ var ValidationTypes = {
340355
}
341356

342357
return result && !expression.hasNext();
358+
359+
},
360+
361+
"<filter-function-list>": function(expression){
362+
var result, part, i;
363+
for (i = 0, result = true; result && expression.hasNext(); i++) {
364+
result = ValidationTypes.isAny(expression, "<filter-function> | <uri>");
365+
}
366+
367+
if (i > 1 && !result) {
368+
// More precise error message if we fail after the first
369+
// parsed <filter-function>.
370+
part = expression.peek();
371+
throw new ValidationError("Expected (<filter-function> | <uri>) but found '" + part.text + "'.", part.line, part.col);
372+
}
373+
374+
return result;
375+
343376
},
344377

345378
"<repeat-style>": function(expression){

tests/css/Validation.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,26 @@
727727
}
728728
}));
729729

730+
suite.add(new ValidationTestCase({
731+
property: "filter",
732+
733+
valid: [
734+
"custom(url(vertexshader.vert) mix(url(fragment.frag) normal source-atop), 4 5, time 0)",
735+
"blur(30px 30px)",
736+
"url('#svgFilter')",
737+
"hue-rotate(10deg)",
738+
"brightness(0.3) contrast(30)",
739+
"brightness(0.3) contrast(30) url(commonfilters.svg#filter)",
740+
"none"
741+
],
742+
743+
invalid: {
744+
"circle(50% at 0 0)" : "Expected (<filter-function-list> | none) but found 'circle(50% at 0 0)'.",
745+
"foo" : "Expected (<filter-function-list> | none) but found 'foo'.",
746+
"blur(30px 30px) none" : "Expected (<filter-function> | <uri>) but found 'none'."
747+
}
748+
}));
749+
730750
["flex", "-ms-flex", "-webkit-flex"].forEach(function(prop_name) {
731751
suite.add(new ValidationTestCase({
732752
property: prop_name,

0 commit comments

Comments
 (0)