[vala/0.36] scanner: Accept backreferences \1 through \99 in regex literals



commit 4ea43e8bd0229a173696a5dcaefb19624d6e933d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed May 16 11:13:19 2018 +0200

    scanner: Accept backreferences \1 through \99 in regex literals
    
    https://bugzilla.gnome.org/show_bug.cgi?id=728574

 tests/Makefile.am           |    1 +
 tests/parser/bug728574.vala |    3 +++
 vala/valageniescanner.vala  |   12 +++++++++++-
 vala/valascanner.vala       |   12 +++++++++++-
 4 files changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7c67a7e..a309eda 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -353,6 +353,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
index 0000000..01fe545
--- /dev/null
+++ b/tests/parser/bug728574.vala
@@ -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)?)?)?)?$/;
+}
diff --git a/vala/valageniescanner.vala b/vala/valageniescanner.vala
index 4afb9f2..91d45b2 100644
--- a/vala/valageniescanner.vala
+++ b/vala/valageniescanner.vala
@@ -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') {
diff --git a/vala/valascanner.vala b/vala/valascanner.vala
index 7c4c75c..063b261 100644
--- a/vala/valascanner.vala
+++ b/vala/valascanner.vala
@@ -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') {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]