]> 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 19:14:44 +0000 (21:14 +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 f27cd25a6b9eca97100d92f9f1872e1ef2644f43..2900039e9339ddeea14ae85563a4c987f43a957e 100644 (file)
@@ -268,6 +268,7 @@ TESTS = \
        gir/bug742012.test \
        gir/bug788775.test \
        gir/delegate-alias-without-target.test \
+       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 f717db66514f97edd60b3014f6b68dba6bb42cde..894ab387d4a46784bff2a6d1e20fd515533dc3f7 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') {