]> granicus.if.org Git - python/commitdiff
#13899: \A, \Z, and \B now correctly match the A, Z, and B literals when used inside...
authorEzio Melotti <ezio.melotti@gmail.com>
Fri, 11 Jan 2013 06:32:01 +0000 (08:32 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Fri, 11 Jan 2013 06:32:01 +0000 (08:32 +0200)
Lib/sre_parse.py
Lib/test/test_re.py
Misc/ACKS
Misc/NEWS

index 9aea56a825b2055acaf061f01d28aeaef9fec5f7..19dd4fc4bce1cd1d9fd80246216a96d5aa7fc0a1 100644 (file)
@@ -235,7 +235,7 @@ def _class_escape(source, escape):
     if code:
         return code
     code = CATEGORIES.get(escape)
-    if code:
+    if code and code[0] == IN:
         return code
     try:
         c = escape[1:2]
index 0c8c676ed8bec0d8e897b5b2ad013336e93c7f62..6b047e48dbb7fa2432fe4d277a50b39e9b2a0f17 100644 (file)
@@ -857,6 +857,12 @@ class ReTests(unittest.TestCase):
         # Test behaviour when not given a string or pattern as parameter
         self.assertRaises(TypeError, re.compile, 0)
 
+    def test_bug_13899(self):
+        # Issue #13899: re pattern r"[\A]" should work like "A" but matches
+        # nothing. Ditto B and Z.
+        self.assertEqual(re.findall(r'[\A\B\b\C\Z]', 'AB\bCZ'),
+                         ['A', 'B', '\b', 'C', 'Z'])
+
     @bigmemtest(size=_2G, memuse=character_size)
     def test_large_search(self, size):
         # Issue #10182: indices were 32-bit-truncated.
index cf2296beb042af091260b68e8011e5439a2b4fd6..d6d81d5cad4f449b465a7cc7cd3edd96302f8e7b 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -65,6 +65,7 @@ Chris Barker
 Anton Barkovsky
 Nick Barnes
 Quentin Barnes
+Matthew Barnett
 Richard Barran
 Cesar Eduardo Barros
 Des Barry
index f4fb8219cce44df9d1a1ddf978ff957cec7dc45a..91706c1e6b6d1ac362fb946ff052348773939d35 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -199,6 +199,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #13899: \A, \Z, and \B now correctly match the A, Z, and B literals
+  when used inside character classes (e.g. '[\A]').  Patch by Matthew Barnett.
+
 - Issue #15545: Fix regression in sqlite3's iterdump method where it was
   failing if the connection used a row factory (such as sqlite3.Row) that
   produced unsortable objects. (Regression was introduced by fix for 9750).