[Python-checkins] cpython: Fixed AttributeError when the regular expression starts from illegal escape.
serhiy.storchaka
python-checkins at python.org
Mon Nov 10 13:40:35 CET 2014
https://hg.python.org/cpython/rev/7972304b9f92
changeset: 93463:7972304b9f92
user: Serhiy Storchaka <storchaka at gmail.com>
date: Mon Nov 10 14:38:16 2014 +0200
summary:
Fixed AttributeError when the regular expression starts from illegal escape.
files:
Lib/sre_parse.py | 1 +
Lib/test/test_re.py | 14 ++++++++++++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -211,6 +211,7 @@
string = str(string, 'latin1')
self.decoded_string = string
self.index = 0
+ self.next = None
self.__next()
def __next(self):
index = self.index
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -531,6 +531,20 @@
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),
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list