cssparser: Don't allow commit_token() on block EOF
authorBenjamin Otte <otte@redhat.com>
Fri, 10 May 2019 15:09:59 +0000 (17:09 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 12 May 2019 15:28:19 +0000 (17:28 +0200)
When we're at the end of a block and gtk_css_parser_get_token() returns
NULL, gtk_css_parser_commit_token() still consumed the next token.

It does not anymore.

This does not affect the CSS parser, but it exposes issues with the
render parser, which previously just consumed too many closing } tokens
in the past.

gtk/css/gtkcssparser.c

index 2ead2e09af1b26210afabdfcf64de7945e003a67..5ba0997b4d608383db412e7d7459843b0d559c74 100644 (file)
@@ -335,7 +335,9 @@ gtk_css_parser_consume_token (GtkCssParser *self)
   /* unpreserved tokens MUST be consumed via start_block() */
   g_assert (gtk_css_token_is_preserved (&self->token, NULL));
 
-  gtk_css_token_clear (&self->token);
+  /* Don't consume any tokens at the end of a block */
+  if (!gtk_css_token_is (gtk_css_parser_peek_token (self), GTK_CSS_TOKEN_EOF))
+    gtk_css_token_clear (&self->token);
 }
 
 void
@@ -435,7 +437,15 @@ gtk_css_parser_end_block (GtkCssParser *self)
   else
     {
       g_array_set_size (self->blocks, self->blocks->len - 1);
-      gtk_css_parser_skip (self);
+      if (gtk_css_token_is_preserved (&self->token, NULL))
+        {
+          gtk_css_token_clear (&self->token);
+        }
+      else
+        {
+          gtk_css_parser_start_block (self);
+          gtk_css_parser_end_block (self);
+        }
     }
 }