[gtk/matthiasc/for-master: 7/8] cssfiltervalue: Reject invalid filters




commit 7e53e189fb9511b4c42917309797f0c9a4c701e1
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Feb 5 22:59:20 2021 -0500

    cssfiltervalue: Reject invalid filters
    
    The Filter Effects Spec doesn't allow negative values
    for most of the filter parameters.

 gtk/gtkcssfiltervalue.c                      | 4 ++--
 testsuite/css/parser/invalid-filter1.css     | 3 +++
 testsuite/css/parser/invalid-filter1.errors  | 1 +
 testsuite/css/parser/invalid-filter1.ref.css | 0
 4 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssfiltervalue.c b/gtk/gtkcssfiltervalue.c
index 0e4c9d46dd..6ee1a57420 100644
--- a/gtk/gtkcssfiltervalue.c
+++ b/gtk/gtkcssfiltervalue.c
@@ -755,7 +755,7 @@ gtk_css_filter_parse_number (GtkCssParser *parser,
 {
   GtkCssValue **values = data;
 
-  values[n] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_NUMBER | GTK_CSS_PARSE_PERCENT);
+  values[n] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_NUMBER | GTK_CSS_PARSE_PERCENT | 
GTK_CSS_POSITIVE_ONLY);
   if (values[n] == NULL)
     return 0;
 
@@ -769,7 +769,7 @@ gtk_css_filter_parse_length (GtkCssParser *parser,
 {
   GtkCssValue **values = data;
 
-  values[n] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH);
+  values[n] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH | GTK_CSS_POSITIVE_ONLY);
   if (values[n] == NULL)
     return 0;
 
diff --git a/testsuite/css/parser/invalid-filter1.css b/testsuite/css/parser/invalid-filter1.css
new file mode 100644
index 0000000000..52580b853e
--- /dev/null
+++ b/testsuite/css/parser/invalid-filter1.css
@@ -0,0 +1,3 @@
+a {
+  filter: blur(-1px);
+}
diff --git a/testsuite/css/parser/invalid-filter1.errors b/testsuite/css/parser/invalid-filter1.errors
new file mode 100644
index 0000000000..b91e500d69
--- /dev/null
+++ b/testsuite/css/parser/invalid-filter1.errors
@@ -0,0 +1 @@
+invalid-filter1.css:2:20-21: error: GTK_CSS_PARSER_ERROR_SYNTAX
diff --git a/testsuite/css/parser/invalid-filter1.ref.css b/testsuite/css/parser/invalid-filter1.ref.css
new file mode 100644
index 0000000000..e69de29bb2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]