mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Fixed AttributeError when the regular expression starts from illegal escape.
This commit is contained in:
parent
ce40e1a081
commit
b99c132bd9
2 changed files with 15 additions and 0 deletions
|
@ -531,6 +531,20 @@ class ReTests(unittest.TestCase):
|
|||
self.assertEqual(re.search(br"\d\D\w\W\s\S",
|
||||
b"1aa! a", re.LOCALE).group(0), b"1aa! a")
|
||||
|
||||
def test_other_escapes(self):
|
||||
self.assertRaises(re.error, re.compile, "\\")
|
||||
self.assertEqual(re.match(r"\(", '(').group(), '(')
|
||||
self.assertIsNone(re.match(r"\(", ')'))
|
||||
self.assertEqual(re.match(r"\\", '\\').group(), '\\')
|
||||
self.assertEqual(re.match(r"\y", 'y').group(), 'y')
|
||||
self.assertIsNone(re.match(r"\y", 'z'))
|
||||
self.assertEqual(re.match(r"[\]]", ']').group(), ']')
|
||||
self.assertIsNone(re.match(r"[\]]", '['))
|
||||
self.assertEqual(re.match(r"[a\-c]", '-').group(), '-')
|
||||
self.assertIsNone(re.match(r"[a\-c]", 'b'))
|
||||
self.assertEqual(re.match(r"[\^a]+", 'a^').group(), 'a^')
|
||||
self.assertIsNone(re.match(r"[\^a]+", 'b'))
|
||||
|
||||
def test_string_boundaries(self):
|
||||
# See http://bugs.python.org/issue10713
|
||||
self.assertEqual(re.search(r"\b(abc)\b", "abc").group(1),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue