]> 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>
Wed, 16 May 2018 11:23:38 +0000 (13:23 +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 21e80f9d7b9bb68a2da1cdfb9cf94320be3a13fe..943e8fea886d27a0851cd64457c1c9e236228f14 100644 (file)
@@ -457,6 +457,7 @@ TESTS = \
        parser/unsupported-property-async.test \
        parser/unsupported-property-throws.test \
        parser/yield-method.test \
+       parser/bug728574.vala \
        parser/bug749576.vala \
        semantic/constant-extern.test \
        semantic/constant-value.test \
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 5ada03a0d92a03851473547ccb99f7fb629def2d..5eb15f02c421281f9e2f83c7ba0be1ff729e323b 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 9af17dc64fec864f873d8aa8230398765c4c411f..718b654717d07b37b7a87fb37360ef0da12296b5 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') {