From: Ezio Melotti Date: Fri, 11 Jan 2013 06:32:01 +0000 (+0200) Subject: #13899: \A, \Z, and \B now correctly match the A, Z, and B literals when used inside... X-Git-Tag: v3.2.4rc1~236 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe8e6e741492c496837a48fc04c5c776c8779b32;p=thirdparty%2FPython%2Fcpython.git #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. --- diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index 9aea56a825b2..19dd4fc4bce1 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -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] diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 0c8c676ed8be..6b047e48dbb7 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -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. diff --git a/Misc/ACKS b/Misc/ACKS index cf2296beb042..d6d81d5cad4f 100644 --- 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 diff --git a/Misc/NEWS b/Misc/NEWS index f4fb8219cce4..91706c1e6b6d 100644 --- 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).