Skip to content

Commit 5cd30a1

Browse files
committed
Merge pull request #190 from cscott/gh-161
Precisely validate <filter-function-list>.
2 parents 6552fc1 + 0afb9a8 commit 5cd30a1

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
@@ -236,6 +236,21 @@ var ValidationTypes = {
236236

237237
"<feature-tag-value>": function(part){
238238
return (part.type === "function" && /^[A-Z0-9]{4}$/i.test(part));
239+
},
240+
241+
"<filter-function>": function(part){
242+
return part.type === "function" && (
243+
part.name === 'blur' ||
244+
part.name === 'brightness' ||
245+
part.name === 'contrast' ||
246+
part.name === 'custom' || // Not actually in formal spec.
247+
part.name === 'drop-shadow' ||
248+
part.name === 'grayscale' ||
249+
part.name === 'hue-rotate' ||
250+
part.name === 'invert' ||
251+
part.name === 'opacity' ||
252+
part.name === 'saturate' ||
253+
part.name === 'sepia');
239254
}
240255
},
241256

@@ -344,6 +359,24 @@ var ValidationTypes = {
344359
}
345360

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

349382
"<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)