diff options
author | Ezio Melotti <ezio.melotti@gmail.com> | 2010-03-06 15:24:08 (GMT) |
---|---|---|
committer | Ezio Melotti <ezio.melotti@gmail.com> | 2010-03-06 15:24:08 (GMT) |
commit | b92ed7cf3673cd9902b785febb895b4e0c7a55ff (patch) | |
tree | 7e0b6a4e0e746f6b102bf41859642107c413761a /Lib/test/test_re.py | |
parent | 64fb18e1921d18c8801e85bf8fc429a4be2160e9 (diff) | |
download | cpython-b92ed7cf3673cd9902b785febb895b4e0c7a55ff.zip cpython-b92ed7cf3673cd9902b785febb895b4e0c7a55ff.tar.gz cpython-b92ed7cf3673cd9902b785febb895b4e0c7a55ff.tar.bz2 |
#6509: fix re.sub to work properly when the pattern, the string, and the replacement were all bytes. Patch by Antoine Pitrou.
Diffstat (limited to 'Lib/test/test_re.py')
-rw-r--r-- | Lib/test/test_re.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index d2f7f6e..5eb9405 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -717,6 +717,24 @@ class ReTests(unittest.TestCase): self.assertRaises(ValueError, re.compile, '(?a)\w', re.UNICODE) self.assertRaises(ValueError, re.compile, '(?au)\w') + def test_bug_6509(self): + # Replacement strings of both types must parse properly. + # all strings + pat = re.compile('a(\w)') + self.assertEqual(pat.sub('b\\1', 'ac'), 'bc') + pat = re.compile('a(.)') + self.assertEqual(pat.sub('b\\1', 'a\u1234'), 'b\u1234') + pat = re.compile('..') + self.assertEqual(pat.sub(lambda m: 'str', 'a5'), 'str') + + # all bytes + pat = re.compile(b'a(\w)') + self.assertEqual(pat.sub(b'b\\1', b'ac'), b'bc') + pat = re.compile(b'a(.)') + self.assertEqual(pat.sub(b'b\\1', b'a\xCD'), b'b\xCD') + pat = re.compile(b'..') + self.assertEqual(pat.sub(lambda m: b'bytes', b'a5'), b'bytes') + def test_dealloc(self): # issue 3299: check for segfault in debug build import _sre |