From: Rico Tzschichholz Date: Mon, 14 May 2018 07:31:32 +0000 (+0200) Subject: scanner: Accept \R and \N escape sequences in regex literals X-Git-Tag: 0.41.90~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b22d43fbdcf807b4e894ca6a502ff620d65001c6;p=thirdparty%2Fvala.git scanner: Accept \R and \N escape sequences in regex literals https://bugzilla.gnome.org/show_bug.cgi?id=749576 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 1658f9252..764ca197f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -456,6 +456,7 @@ TESTS = \ parser/unsupported-property-async.test \ parser/unsupported-property-throws.test \ parser/yield-method.test \ + parser/bug749576.vala \ semantic/constant-extern.test \ semantic/constant-value.test \ semantic/constant-value-missing.test \ diff --git a/tests/parser/bug749576.vala b/tests/parser/bug749576.vala new file mode 100644 index 000000000..8aa961af0 --- /dev/null +++ b/tests/parser/bug749576.vala @@ -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 { + } +} diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala index 177f2b027..de49d9df2 100644 --- a/vala/valageniescanner.vala +++ b/vala/valageniescanner.vala @@ -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': diff --git a/vala/valascanner.vala b/vala/valascanner.vala index 2cb705064..9af17dc64 100644 --- a/vala/valascanner.vala +++ b/vala/valascanner.vala @@ -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':