forked from AuroraMiddleware/gtk
csstokenizer: Handle backslash at end of document
Testcases included.
This commit is contained in:
parent
24d6ce7e51
commit
bc7972dfa7
@ -633,13 +633,6 @@ is_name (char c)
|
||||
|| c == '-';
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_valid_escape (char c1, char c2)
|
||||
{
|
||||
return c1 == '\\'
|
||||
&& !is_newline (c2);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_non_printable (char c)
|
||||
{
|
||||
@ -650,6 +643,25 @@ is_non_printable (char c)
|
||||
|| c == 0x7F;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
is_valid_escape (const char *data,
|
||||
const char *end)
|
||||
{
|
||||
switch (end - data)
|
||||
{
|
||||
default:
|
||||
if (is_newline (data[1]))
|
||||
return FALSE;
|
||||
G_GNUC_FALLTHROUGH;
|
||||
|
||||
case 1:
|
||||
return data[0] == '\\';
|
||||
|
||||
case 0:
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
static inline gsize
|
||||
gtk_css_tokenizer_remaining (GtkCssTokenizer *tokenizer)
|
||||
{
|
||||
@ -659,15 +671,7 @@ gtk_css_tokenizer_remaining (GtkCssTokenizer *tokenizer)
|
||||
static gboolean
|
||||
gtk_css_tokenizer_has_valid_escape (GtkCssTokenizer *tokenizer)
|
||||
{
|
||||
switch (gtk_css_tokenizer_remaining (tokenizer))
|
||||
{
|
||||
case 0:
|
||||
return FALSE;
|
||||
case 1:
|
||||
return *tokenizer->data == '\\';
|
||||
default:
|
||||
return is_valid_escape (tokenizer->data[0], tokenizer->data[1]);
|
||||
}
|
||||
return is_valid_escape (tokenizer->data, tokenizer->end);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -814,7 +818,11 @@ gtk_css_tokenizer_read_escape (GtkCssTokenizer *tokenizer)
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
value = g_utf8_get_char_validated (tokenizer->data, gtk_css_tokenizer_remaining (tokenizer));
|
||||
gsize remaining = gtk_css_tokenizer_remaining (tokenizer);
|
||||
if (remaining == 0)
|
||||
return 0xFFFD;
|
||||
|
||||
value = g_utf8_get_char_validated (tokenizer->data, remaining);
|
||||
if (value == (gunichar) -1 || value == (gunichar) -2)
|
||||
value = 0;
|
||||
|
||||
|
2
testsuite/css/parser/backslash-eof-is-identifier.css
Normal file
2
testsuite/css/parser/backslash-eof-is-identifier.css
Normal file
@ -0,0 +1,2 @@
|
||||
a {
|
||||
animation-name: \
|
2
testsuite/css/parser/backslash-eof-is-identifier.errors
Normal file
2
testsuite/css/parser/backslash-eof-is-identifier.errors
Normal file
@ -0,0 +1,2 @@
|
||||
backslash-eof-is-identifier.css:2:3-20: error: GTK_CSS_PARSER_WARNING_SYNTAX
|
||||
backslash-eof-is-identifier.css:1:3-2:20: error: GTK_CSS_PARSER_WARNING_SYNTAX
|
3
testsuite/css/parser/backslash-eof-is-identifier.ref.css
Normal file
3
testsuite/css/parser/backslash-eof-is-identifier.ref.css
Normal file
@ -0,0 +1,3 @@
|
||||
a {
|
||||
animation-name: <EFBFBD>;
|
||||
}
|
1
testsuite/css/parser/backslash.css
Normal file
1
testsuite/css/parser/backslash.css
Normal file
@ -0,0 +1 @@
|
||||
\
|
1
testsuite/css/parser/backslash.errors
Normal file
1
testsuite/css/parser/backslash.errors
Normal file
@ -0,0 +1 @@
|
||||
backslash.css:1:2: error: GTK_CSS_PARSER_ERROR_SYNTAX
|
0
testsuite/css/parser/backslash.ref.css
Normal file
0
testsuite/css/parser/backslash.ref.css
Normal file
@ -160,6 +160,12 @@ test_data = [
|
||||
'background-shorthand-single.ref.css',
|
||||
'background-size.css',
|
||||
'background-size.ref.css',
|
||||
'backslash.css',
|
||||
'backslash.errors',
|
||||
'backslash.ref.css',
|
||||
'backslash-eof-is-identifier.css',
|
||||
'backslash-eof-is-identifier.errors',
|
||||
'backslash-eof-is-identifier.ref.css',
|
||||
'border-color.css',
|
||||
'border-color-currentcolor.css',
|
||||
'border-color-currentcolor.ref.css',
|
||||
|
Loading…
Reference in New Issue
Block a user