diff options
author | Brett Cannon <bcannon@gmail.com> | 2003-04-19 04:00:56 +0000 |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2003-04-19 04:00:56 +0000 |
commit | 2c46a572a427b7f9ad98832787d97dd0e81c122c (patch) | |
tree | abc747679e60f57d1d180212addb506f8be336ee /Lib/_strptime.py | |
parent | 1ac254287c9516ee1162b66e08eb9001695b69a5 (diff) | |
download | cpython-2c46a572a427b7f9ad98832787d97dd0e81c122c.tar.gz |
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.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py index 55391c1f7d..0777b7e801 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: |