summaryrefslogtreecommitdiff
path: root/dev-python/backrefs/files/backrefs-5.2-fix-regex-unrecognized-escape.patch
blob: 6bb217d1f66e200022be5449cd85d24bd38f6e45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
From 78577debb9127ace54101f77e669d7c674476803 Mon Sep 17 00:00:00 2001
From: facelessuser <faceless.shop@gmail.com>
Date: Fri, 8 Apr 2022 18:35:00 -0600
Subject: [PATCH] Fixes for recent regex library handling of unrecognized
 escapes

---
 tests/test_bre.py    |  4 +--
 tests/test_bregex.py | 60 +++++++++++++++++++++-----------------------
 2 files changed, 30 insertions(+), 34 deletions(-)

diff --git a/tests/test_bre.py b/tests/test_bre.py
index d88fe86..64b9a57 100644
--- a/tests/test_bre.py
+++ b/tests/test_bre.py
@@ -1464,7 +1464,7 @@ def test_escaped_slash_before_backref(self):
 
         self.assertEqual(r'\\test: \This is a test of escaped slash backrefs!', results)
 
-    def test_normal_escaping(self):
+    def test_normal_escaping_replace(self):
         """Test normal escaped slash."""
 
         text = "This is a test of normal escaping!"
@@ -1478,7 +1478,7 @@ def test_normal_escaping(self):
         self.assertEqual(results2, results)
         self.assertEqual('\t \\t \\\t \\\\t \\\\\t', results)
 
-    def test_bytes_normal_escaping(self):
+    def test_bytes_normal_escaping_replace(self):
         """Test bytes normal escaped slash."""
 
         text = b"This is a test of normal escaping!"
diff --git a/tests/test_bregex.py b/tests/test_bregex.py
index 929227a..5a3d0af 100644
--- a/tests/test_bregex.py
+++ b/tests/test_bregex.py
@@ -801,12 +801,10 @@ def test_bytes_line_break(self):
         )
 
     def test_line_break_in_group(self):
-        """Test that line break in group matches a normal R."""
+        """Test that line break in group fails."""
 
-        self.assertEqual(
-            bregex.sub(r"[\R]", 'l', 'Rine\r\nRine\nRine\r'),
-            'line\r\nline\nline\r'
-        )
+        with self.assertRaises(_regex_core.error):
+            bregex.sub(r"[\R]", 'l', 'Rine\r\nRine\nRine\r')
 
     def test_replace_unicode_name_ascii_range(self):
         """Test replacing Unicode names in the ASCII range."""
@@ -1176,33 +1174,33 @@ def test_escaped_slash_before_backref(self):
 
         self.assertEqual(r'\\test: \This is a test of escaped slash backrefs!', results)
 
-    def test_normal_escaping(self):
+    def test_normal_escaping_replace(self):
         """Test normal escaped slash."""
 
         text = "This is a test of normal escaping!"
         pattern = regex.compile(r"(.+)")
-        repl_pattern = r'\e \\e \\\e \\\\e \\\\\e'
+        repl_pattern = r'\t \\t \\\t \\\\t \\\\\t'
         expand = bregex.compile_replace(pattern, repl_pattern)
         m = pattern.match(text)
         results = expand(m)
         results2 = pattern.sub(repl_pattern, text)
 
         self.assertEqual(results2, results)
-        self.assertEqual('\\e \\e \\\\e \\\\e \\\\\\e', results)
+        self.assertEqual('\t \\t \\\t \\\\t \\\\\t', results)
 
-    def test_bytes_normal_escaping(self):
+    def test_bytes_normal_escaping_replace(self):
         """Test bytes normal escaped slash."""
 
         text = b"This is a test of normal escaping!"
         pattern = regex.compile(br"(.+)")
-        repl_pattern = br'\e \\e \\\e \\\\e \\\\\e'
+        repl_pattern = br'\t \\t \\\t \\\\t \\\\\t'
         expand = bregex.compile_replace(pattern, repl_pattern)
         m = pattern.match(text)
         results = expand(m)
         results2 = pattern.sub(repl_pattern, text)
 
         self.assertEqual(results2, results)
-        self.assertEqual(b'\\e \\e \\\\e \\\\e \\\\\\e', results)
+        self.assertEqual(b'\t \\t \\\t \\\\t \\\\\t', results)
 
     def test_escaped_slash_at_eol(self):
         """Test escaped slash at end of line."""
@@ -1214,15 +1212,12 @@ def test_escaped_slash_at_eol(self):
 
         self.assertEqual('\\\\', results)
 
-    def test_unrecognized_backrefs(self):
+    def test_unrecognized_backrefs2(self):
         """Test unrecognized backrefs, or literal backslash before a char."""
 
-        text = "This is a test of unrecognized backrefs!"
         pattern = regex.compile(r"(.+)")
-        expand = bregex.compile_replace(pattern, r'\k\1')
-        results = expand(pattern.match(text))
-
-        self.assertEqual(r'\kThis is a test of unrecognized backrefs!', results)
+        with self.assertRaises(_regex_core.error):
+            bregex.compile_replace(pattern, r'\k\1')
 
     def test_ignore_group(self):
         """Test that backrefs inserted by matching groups are passed over."""
@@ -1628,23 +1623,23 @@ def test_dont_case_special_refs(self):
         self.assertEqual('\u0108\nWw\u0108', results)
 
         # Bytes doesn't care about Unicode, but should evaluate bytes
-        pattern = regex.compile(b'Test')
-        expand = bregex.compile_replace(pattern, br'\C\u0109\n\x77\E\l\x57\c\u0109')
-        results = expand(pattern.match(b'Test'))
-        self.assertEqual(b'\\U0109\nWw\\u0109', results)
+        # pattern = regex.compile(b'Test')
+        # expand = bregex.compile_replace(pattern, br'\C\u0109\n\x77\E\l\x57\c\u0109')
+        # results = expand(pattern.match(b'Test'))
+        # self.assertEqual(b'\\U0109\nWw\\u0109', results)
 
-        expandf = bregex.compile_replace(pattern, br'\C\u0109\n\x77\E\l\x57\c\u0109', bregex.FORMAT)
-        results = expandf(pattern.match(b'Test'))
-        self.assertEqual(b'\\U0109\nWw\\u0109', results)
+        # expandf = bregex.compile_replace(pattern, br'\C\u0109\n\x77\E\l\x57\c\u0109', bregex.FORMAT)
+        # results = expandf(pattern.match(b'Test'))
+        # self.assertEqual(b'\\U0109\nWw\\u0109', results)
 
-        pattern = regex.compile(b'Test')
-        expand = bregex.compile_replace(pattern, br'\C\U00000109\n\x77\E\l\x57\c\U00000109')
-        results = expand(pattern.match(b'Test'))
-        self.assertEqual(b'\U00000109\nWw\U00000109', results)
+        # pattern = regex.compile(b'Test')
+        # expand = bregex.compile_replace(pattern, br'\C\U00000109\n\x77\E\l\x57\c\U00000109')
+        # results = expand(pattern.match(b'Test'))
+        # self.assertEqual(b'\U00000109\nWw\U00000109', results)
 
-        expandf = bregex.compile_replace(pattern, br'\C\U00000109\n\x77\E\l\x57\c\U00000109', bregex.FORMAT)
-        results = expandf(pattern.match(b'Test'))
-        self.assertEqual(b'\U00000109\nWw\U00000109', results)
+        # expandf = bregex.compile_replace(pattern, br'\C\U00000109\n\x77\E\l\x57\c\U00000109', bregex.FORMAT)
+        # results = expandf(pattern.match(b'Test'))
+        # self.assertEqual(b'\U00000109\nWw\U00000109', results)
 
         # Format doesn't care about groups
         pattern = regex.compile('Test')
@@ -2184,4 +2179,5 @@ def test_auto_compile_off(self):
         replace = p.compile(r'{1}', bregex.FORMAT)
         self.assertEqual(p.subf(replace, 'tests'), 'test')
 
-        self.assertEqual(p.sub(r'\ltest', 'tests'), r'\ltest')
+        with self.assertRaises(_regex_core.error):
+            self.assertEqual(p.sub(r'\ltest', 'tests'), r'\ltest')