Merge branch 'css-var-syntax-errors' into 'main'
css: Report some var() syntax errors See merge request GNOME/gtk!7264
This commit is contained in:
@@ -1482,9 +1482,9 @@ gtk_css_parser_parse_value_into_token_stream (GtkCssParser *self)
|
||||
GtkCssVariableValueReference ref;
|
||||
char *var_name = g_strdup (gtk_css_token_get_string (token));
|
||||
|
||||
if (var_name[0] != '-' || var_name[1] != '-')
|
||||
if (strlen (var_name) < 3 || var_name[0] != '-' || var_name[1] != '-')
|
||||
{
|
||||
gtk_css_parser_error_value (self, "Invalid variable name: %s", var_name);
|
||||
gtk_css_parser_error_syntax (self, "Invalid variable name: %s", var_name);
|
||||
g_free (var_name);
|
||||
goto error;
|
||||
}
|
||||
@@ -1527,6 +1527,20 @@ gtk_css_parser_parse_value_into_token_stream (GtkCssParser *self)
|
||||
|
||||
gtk_css_parser_references_append (&refs, &ref);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gtk_css_token_is (token, GTK_CSS_TOKEN_EOF))
|
||||
{
|
||||
gtk_css_parser_error_syntax (self, "Missing variable name");
|
||||
}
|
||||
else
|
||||
{
|
||||
char *s = gtk_css_token_to_string (token);
|
||||
gtk_css_parser_error_syntax (self, "Expected a variable name, not %s", s);
|
||||
g_free (s);
|
||||
}
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
testsuite/css/parser/variables-invalid-07.css
Normal file
15
testsuite/css/parser/variables-invalid-07.css
Normal file
@@ -0,0 +1,15 @@
|
||||
a {
|
||||
--accent-fg-color: var();
|
||||
}
|
||||
|
||||
b {
|
||||
--accent-fg-color: var(-);
|
||||
}
|
||||
|
||||
c {
|
||||
--accent-fg-color: var(a);
|
||||
}
|
||||
|
||||
d {
|
||||
--accent-fg-color: var(21);
|
||||
}
|
||||
4
testsuite/css/parser/variables-invalid-07.errors
Normal file
4
testsuite/css/parser/variables-invalid-07.errors
Normal file
@@ -0,0 +1,4 @@
|
||||
variables-invalid-07.css:2:26-27: error: GTK_CSS_PARSER_ERROR_SYNTAX
|
||||
variables-invalid-07.css:6:26-27: error: GTK_CSS_PARSER_ERROR_SYNTAX
|
||||
variables-invalid-07.css:10:26-27: error: GTK_CSS_PARSER_ERROR_SYNTAX
|
||||
variables-invalid-07.css:14:26-28: error: GTK_CSS_PARSER_ERROR_SYNTAX
|
||||
0
testsuite/css/parser/variables-invalid-07.ref.css
Normal file
0
testsuite/css/parser/variables-invalid-07.ref.css
Normal file
Reference in New Issue
Block a user