]> granicus.if.org Git - python/commitdiff
Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh:
authorGuido van Rossum <guido@python.org>
Thu, 3 Jan 2008 19:08:15 +0000 (19:08 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 3 Jan 2008 19:08:15 +0000 (19:08 +0000)
Regular Expression inline flags not handled correctly for some unicode
characters.

Lib/sre_compile.py
Lib/test/test_re.py
Misc/NEWS

index 71095991ecc96961880c768ecedb9dd3d716231f..22ab2fd14889314d7f733728d03850133c1e6b72 100644 (file)
@@ -525,7 +525,7 @@ def compile(p, flags=0):
         indexgroup[i] = k
 
     return _sre.compile(
-        pattern, flags, code,
+        pattern, flags | p.pattern.flags, code,
         p.pattern.groups-1,
         groupindex, indexgroup
         )
index 3f81993d1430328e2ff56694dbdabad02c4f784f..7d8eab87ff6044d9d462083ad4c9090610b4f407 100644 (file)
@@ -637,6 +637,36 @@ class ReTests(unittest.TestCase):
             self.assertEqual(re.compile("bla").match(a), None)
             self.assertEqual(re.compile("").match(a).groups(), ())
 
+    def test_inline_flags(self):
+        # Bug #1700
+        upper_char = unichr(0x1ea0) # Latin Capital Letter A with Dot Bellow
+        lower_char = unichr(0x1ea1) # Latin Small Letter A with Dot Bellow
+
+        p = re.compile(upper_char, re.I | re.U)
+        q = p.match(lower_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile(lower_char, re.I | re.U)
+        q = p.match(upper_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile('(?i)' + upper_char, re.U)
+        q = p.match(lower_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile('(?i)' + lower_char, re.U)
+        q = p.match(upper_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile('(?iu)' + upper_char)
+        q = p.match(lower_char)
+        self.assertNotEqual(q, None)
+
+        p = re.compile('(?iu)' + lower_char)
+        q = p.match(upper_char)
+        self.assertNotEqual(q, None)
+
+
 def run_re_tests():
     from test.re_tests import benchmarks, tests, SUCCEED, FAIL, SYNTAX_ERROR
     if verbose:
index 38a047d38ae319afd12182e655238bd3a3b1ec5f..97027a3cbbd805a269b41b015f5a3791bbb44e3e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -53,6 +53,9 @@ Core and builtins
 Library
 -------
 
+- Issue #1700: Regular expression inline flags incorrectly handle certain
+  unicode characters.
+
 - Change ctypes version number to 1.0.3 (when Python 2.5.2 is released,
   ctypes 1.0.3 will be also be released).