csstokenizer: Consume the \ when encountering an error
authorBenjamin Otte <otte@redhat.com>
Mon, 6 May 2019 03:56:06 +0000 (05:56 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 6 May 2019 03:56:06 +0000 (05:56 +0200)
Otherwise we infinitely end up with the error again.

Testcases added.

gtk/css/gtkcsstokenizer.c
testsuite/css/parser/meson.build
testsuite/css/parser/newline-after-backslash-original.css [new file with mode: 0644]
testsuite/css/parser/newline-after-backslash-original.errors [new file with mode: 0644]
testsuite/css/parser/newline-after-backslash-original.ref.css [new file with mode: 0644]
testsuite/css/parser/newline-after-backslash.css [new file with mode: 0644]
testsuite/css/parser/newline-after-backslash.errors [new file with mode: 0644]
testsuite/css/parser/newline-after-backslash.ref.css [new file with mode: 0644]

index b956c865048662f83ba55b64e7d85791ca793064..90e781c04fe053e71705cb6014a01da5329e73a4 100644 (file)
@@ -1376,6 +1376,7 @@ gtk_css_tokenizer_read_token (GtkCssTokenizer  *tokenizer,
       else
         {
           gtk_css_token_init (token, GTK_CSS_TOKEN_DELIM, '\\');
+          gtk_css_tokenizer_consume_ascii (tokenizer);
           gtk_css_tokenizer_parse_error (error, "Newline may not follow '\' escape character");
           return FALSE;
         }
index bedebff64e9605533198ad6cf04dfea350076ef5..4ab3fbb305bdb03dca5c72e0b9da0ea4652f6b1d 100644 (file)
@@ -347,6 +347,12 @@ test_data = [
   'min-height.ref.css',
   'min-width.css',
   'min-width.ref.css',
+  'newline-after-backslash.css',
+  'newline-after-backslash.errors',
+  'newline-after-backslash.ref.css',
+  'newline-after-backslash-original.css',
+  'newline-after-backslash-original.errors',
+  'newline-after-backslash-original.ref.css',
   'no-semicolon.css',
   'no-semicolon.errors',
   'no-semicolon.ref.css',
diff --git a/testsuite/css/parser/newline-after-backslash-original.css b/testsuite/css/parser/newline-after-backslash-original.css
new file mode 100644 (file)
index 0000000..1c5d0c1
--- /dev/null
@@ -0,0 +1,24 @@
+/*\r
+You can type here any CSS rule recognized by GTK.\r
+You can temporarily disable this custom CSS by clicking on the “Pause” button above.\r
+\r
+Changes are applied instantly and globally, for the whole application.\r
+*/\r
+\r
+\r
+modelbutton.flat:hover {\r
+  background-color: red;\r
+}\r
+\r
+popover arrow {\r
+  background-color: lime;\r
+  border-width: 2px;\r
+  border-color: green;\r
+}\r
+\r
+popover {\r
+}\r
+\\r
+popover contents {\r
+  background-color: magenta;\r
+}
\ No newline at end of file
diff --git a/testsuite/css/parser/newline-after-backslash-original.errors b/testsuite/css/parser/newline-after-backslash-original.errors
new file mode 100644 (file)
index 0000000..8b4ff42
--- /dev/null
@@ -0,0 +1 @@
+newline-after-backslash-original.css:21:1-2: error: GTK_CSS_PARSER_ERROR_SYNTAX
diff --git a/testsuite/css/parser/newline-after-backslash-original.ref.css b/testsuite/css/parser/newline-after-backslash-original.ref.css
new file mode 100644 (file)
index 0000000..1f34fb3
--- /dev/null
@@ -0,0 +1,18 @@
+popover {
+}
+
+popover arrow {
+  background-color: rgb(0,255,0);
+  border-bottom-color: rgb(0,128,0);
+  border-bottom-width: 2px;
+  border-left-color: rgb(0,128,0);
+  border-left-width: 2px;
+  border-right-color: rgb(0,128,0);
+  border-right-width: 2px;
+  border-top-color: rgb(0,128,0);
+  border-top-width: 2px;
+}
+
+modelbutton:hover.flat {
+  background-color: rgb(255,0,0);
+}
diff --git a/testsuite/css/parser/newline-after-backslash.css b/testsuite/css/parser/newline-after-backslash.css
new file mode 100644 (file)
index 0000000..1233d0e
--- /dev/null
@@ -0,0 +1 @@
+\\r
diff --git a/testsuite/css/parser/newline-after-backslash.errors b/testsuite/css/parser/newline-after-backslash.errors
new file mode 100644 (file)
index 0000000..157d994
--- /dev/null
@@ -0,0 +1 @@
+newline-after-backslash.css:1:1-2: error: GTK_CSS_PARSER_ERROR_SYNTAX
diff --git a/testsuite/css/parser/newline-after-backslash.ref.css b/testsuite/css/parser/newline-after-backslash.ref.css
new file mode 100644 (file)
index 0000000..e69de29