mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
css: Report some var() syntax errors
Detect cases such as var(), var(-), var("a") or var(21) early and report them as syntax errors. Test included. Related: #6715
This commit is contained in:
parent
af0c277bba
commit
b60c60f03b
@ -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
Loading…
Reference in New Issue
Block a user