summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2007-12-19 18:13:31 (GMT)
committerRaymond Hettinger <python@rcn.com>2007-12-19 18:13:31 (GMT)
commit80016c95554677cd172610501446b096edfb267c (patch)
tree114f9f7ea92a5a63e2b1d40b30354f1962558ea4 /Lib
parent0f5e7bf3049408d6f4c1855807204c9f13ae98f9 (diff)
downloadcpython-80016c95554677cd172610501446b096edfb267c.zip
cpython-80016c95554677cd172610501446b096edfb267c.tar.gz
cpython-80016c95554677cd172610501446b096edfb267c.tar.bz2
Fix issue 1661: Flags argument silently ignored in re functions with compiled regexes.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/re.py2
-rw-r--r--Lib/test/test_re.py8
2 files changed, 10 insertions, 0 deletions
diff --git a/Lib/re.py b/Lib/re.py
index a33e34e..39e81fd 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -224,6 +224,8 @@ def _compile(*key):
return p
pattern, flags = key
if isinstance(pattern, _pattern_type):
+ if flags:
+ raise ValueError('Cannot process flags argument with a compiled pattern')
return pattern
if not sre_compile.isstring(pattern):
raise TypeError, "first argument must be string or compiled pattern"
diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py
index aa403ba..f1fdfba 100644
--- a/Lib/test/test_re.py
+++ b/Lib/test/test_re.py
@@ -108,6 +108,14 @@ class ReTests(unittest.TestCase):
self.assertEqual(z, y)
self.assertEqual(type(z), type(y))
+ def test_bug_1661(self):
+ # Verify that flags do not get silently ignored with compiled patterns
+ pattern = re.compile('.')
+ self.assertRaises(ValueError, re.match, pattern, 'A', re.I)
+ self.assertRaises(ValueError, re.search, pattern, 'A', re.I)
+ self.assertRaises(ValueError, re.findall, pattern, 'A', re.I)
+ self.assertRaises(ValueError, re.compile, pattern, re.I)
+
def test_sub_template_numeric_escape(self):
# bug 776311 and friends
self.assertEqual(re.sub('x', r'\0', 'x'), '\0')