]> 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 7149dca491bca7f807b2fd88b48fe4a405a49995..8b98b1ac2ed72bc94b801b45c37771b46ddcfe88 100644 (file)
@@ -228,7 +228,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 70702e63483d62d07e99116f7f550d617fccc8f5..dee5efee8ec66ee40f8d53d5c1facc72257cf07a 100644 (file)
@@ -821,6 +821,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'])
+
     @precisionbigmemtest(size=_2G, memuse=1)
     def test_large_search(self, size):
         # Issue #10182: indices were 32-bit-truncated.
index 41c684f09aae48251a2e68677a08c9ab8fc3457f..c1856892276b20cab897c0e993f5a682e3322871 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -58,6 +58,7 @@ Chris Barker
 Anton Barkovsky
 Nick Barnes
 Quentin Barnes
+Matthew Barnett
 Richard Barran
 Cesar Eduardo Barros
 Des Barry
index 469ca8b2fa3f4c5220a6825fbb99be68aee191bb..1f4e282d2cfb1901ed0b40256ef6aa32b5ef618a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -186,6 +186,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 #15109: Fix regression in sqlite3's iterdump method where it would
   die with an encoding error if the database contained string values
   containing non-ASCII.  (Regression was introduced by fix for 9750).