summaryrefslogtreecommitdiffstats
path: root/Lib/_strptime.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2003-04-19 04:00:56 (GMT)
committerBrett Cannon <bcannon@gmail.com>2003-04-19 04:00:56 (GMT)
commit1e91d8eb030656386ef3a07e8a516683bea85610 (patch)
tree45c19f32c4afa76c165b390f33a73c756a2ee4de /Lib/_strptime.py
parent482c5f7eb7eb5408dd48359571b12543732604dc (diff)
downloadcpython-1e91d8eb030656386ef3a07e8a516683bea85610.zip
cpython-1e91d8eb030656386ef3a07e8a516683bea85610.tar.gz
cpython-1e91d8eb030656386ef3a07e8a516683bea85610.tar.bz2
Make _strptime escape regex syntax in format string to prevent use in internal regex.
Diffstat (limited to 'Lib/_strptime.py')
-rw-r--r--Lib/_strptime.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index 55391c1..0777b7e 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -373,8 +373,17 @@ class TimeRE(dict):
return '%s)' % regex
def pattern(self, format):
- """Return re pattern for the format string."""
+ """Return re pattern for the format string.
+
+ Need to make sure that any characters that might be interpreted as
+ regex syntax is escaped.
+
+ """
processed_format = ''
+ # The sub() call escapes all characters that might be misconstrued
+ # as regex syntax.
+ regex_chars = re_compile(r"([\\.^$*+?{}\[\]|])")
+ format = regex_chars.sub(r"\\\1", format)
whitespace_replacement = re_compile('\s+')
format = whitespace_replacement.sub('\s*', format)
while format.find('%') != -1: