]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
_strptime.srptime() escaped parentheses in the format string properly.
authorBrett Cannon <bcannon@gmail.com>
Fri, 29 Aug 2003 02:34:22 +0000 (02:34 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 29 Aug 2003 02:34:22 +0000 (02:34 +0000)
Closes bug #796149 .

Lib/_strptime.py
Lib/test/test_strptime.py
Misc/NEWS

index b3db42e0f69af298d9fc6e65373e825681b84fc1..1d05869f0d7216c5e60153de591f838c9fee49ea 100644 (file)
@@ -381,7 +381,7 @@ class TimeRE(dict):
         processed_format = ''
         # The sub() call escapes all characters that might be misconstrued
         # as regex syntax.
-        regex_chars = re_compile(r"([\\.^$*+?{}\[\]|])")
+        regex_chars = re_compile(r"([\\.^$*+?i\(\){}\[\]|])")
         format = regex_chars.sub(r"\\\1", format)
         whitespace_replacement = re_compile('\s+')
         format = whitespace_replacement.sub('\s*', format)
index 919f7416e8e422ff111f739552554cadf937a223..869954c1ec5875f0f21f50b6a68e0afe1b4a9f57 100644 (file)
@@ -383,6 +383,15 @@ class StrptimeTests(unittest.TestCase):
                         "Default values for strptime() are incorrect;"
                         " %s != %s" % (strp_output, defaults))
 
+    def test_escaping(self):
+        # Make sure all characters that have regex significance are escaped.
+        # Parentheses are in a purposeful order; will cause an error of
+        # unbalanced parentheses when the regex is compiled if they are not
+        # escaped.
+        # Test instigated by bug #796149 .
+        need_escaping = ".^$*+?{}\[]|)("
+        self.failUnless(_strptime.strptime(need_escaping, need_escaping))
+
 class Strptime12AMPMTests(unittest.TestCase):
     """Test a _strptime regression in '%I %p' at 12 noon (12 PM)"""
 
index 9c6152bb2e5ecdb423ece9bf84237b4f16029867..b2d1a2d6f146dff8f581b5200e55f2af1f90366a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -30,6 +30,9 @@ Extension modules
 Library
 -------
 
+- Bug #796149: time.strptime() now handles having parentheses in the
+  format string properly.
+
 - The email package handles some RFC 2231 parameters with missing
   CHARSET fields better.