]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
scanner: Accept \R and \N escape sequences in regex literals
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 14 May 2018 07:31:32 +0000 (09:31 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 21 May 2018 16:19:00 +0000 (18:19 +0200)
https://bugzilla.gnome.org/show_bug.cgi?id=749576

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

index f64269fb1342fa8e68dd3890ec37b8d3be9b7b23..f9dfaffd0c708298f5c79a995ef404d46a943a6b 100644 (file)
@@ -355,6 +355,7 @@ TESTS = \
        parser/preprocessor.vala \
        parser/template.vala \
        parser/tuple.vala \
+       parser/bug749576.vala \
        $(NULL)
 
 NON_NULL_TESTS = \
diff --git a/tests/parser/bug749576.vala b/tests/parser/bug749576.vala
new file mode 100644 (file)
index 0000000..8aa961a
--- /dev/null
@@ -0,0 +1,29 @@
+void main() {
+       unowned string a = "first line\nnext line";
+       unowned string b = "first line\rnext line";
+       unowned string c = "first \tline\r\nnext \tline";
+
+       assert (/\Rnext/.match (a));
+       assert (/\Rnext/.match (b));
+       assert (/\Rnext/.match (c));
+
+       try {
+               var r = new Regex ("\\Rnext");
+               assert (r.match (a));
+
+               var r2 = new Regex ("""\Rnext""");
+               assert (r2.match (a));
+       } catch {
+       }
+
+       assert (/\Nline/.match (c));
+
+       try {
+               var r = new Regex ("\\Nline");
+               assert (r.match (c));
+
+               var r2 = new Regex ("""\Nline""");
+               assert (r2.match (c));
+       } catch {
+       }
+}
index e232a77bc44e281e285cb4c8ff9d4ce65ff0f5f9..d5d013642083320bab11425944d1616db1244c01 100644 (file)
@@ -208,7 +208,9 @@ public class Vala.Genie.Scanner {
                                                case 'B':
                                                case 'f':
                                                case 'n':
+                                               case 'N':
                                                case 'r':
+                                               case 'R':
                                                case 't':
                                                case 'a':
                                                case 'A':
index 8b50a59d4eb94c90b80796c7a316b886f334e867..7c4c75c0c2ad340210ec33c961bfc54b832fcba8 100644 (file)
@@ -193,7 +193,9 @@ public class Vala.Scanner {
                                                case 'B':
                                                case 'f':
                                                case 'n':
+                                               case 'N':
                                                case 'r':
+                                               case 'R':
                                                case 't':
                                                case 'v':
                                                case 'a':