]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
scanner: Accept backreferences \1 through \99 in regex literals
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 16 May 2018 09:13:19 +0000 (11:13 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 21 May 2018 16:20:42 +0000 (18:20 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=728574

tests/Makefile.am
tests/parser/bug728574.vala [new file with mode: 0644]
vala/valageniescanner.vala
vala/valascanner.vala

index f9dfaffd0c708298f5c79a995ef404d46a943a6b..7b886882a4ccc9279d8cd43505b732ab43793b56 100644 (file)
@@ -355,6 +355,7 @@ TESTS = \
        parser/preprocessor.vala \
        parser/template.vala \
        parser/tuple.vala \
+       parser/bug728574.vala \
        parser/bug749576.vala \
        $(NULL)
 
diff --git a/tests/parser/bug728574.vala b/tests/parser/bug728574.vala
new file mode 100644 (file)
index 0000000..01fe545
--- /dev/null
@@ -0,0 +1,3 @@
+void main () {
+       var r = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24\:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
+}
index 4afb9f28d106950283803d9d3d61e528d83de514..91d45b2f5206128e348c93cd69692aea4f83f374 100644 (file)
@@ -240,7 +240,17 @@ public class Vala.Genie.Scanner {
                                                        }
                                                        break;
                                                default:
-                                                       Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
+                                                       // back references \1 through \99
+                                                       if (current[0].isdigit ()) {
+                                                               current++;
+                                                               token_length_in_chars++;
+                                                               if (current[0].isdigit ()) {
+                                                                       current++;
+                                                                       token_length_in_chars++;
+                                                               }
+                                                       } else {
+                                                               Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
+                                                       }
                                                        break;
                                                }
                                        } else if (current[0] == '\n') {
index 7c4c75c0c2ad340210ec33c961bfc54b832fcba8..063b261bece1d89e659b759d3bf366707cefe195 100644 (file)
@@ -242,7 +242,17 @@ public class Vala.Scanner {
                                                        }
                                                        break;
                                                default:
-                                                       Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
+                                                       // back references \1 through \99
+                                                       if (current[0].isdigit ()) {
+                                                               current++;
+                                                               token_length_in_chars++;
+                                                               if (current[0].isdigit ()) {
+                                                                       current++;
+                                                                       token_length_in_chars++;
+                                                               }
+                                                       } else {
+                                                               Report.error (get_source_reference (token_length_in_chars), "invalid escape sequence");
+                                                       }
                                                        break;
                                                }
                                        } else if (current[0] == '\n') {