[Python-checkins] python/dist/src/Lib _strptime.py,1.13,1.14
bcannon@users.sourceforge.net
bcannon@users.sourceforge.net
Fri, 18 Apr 2003 21:00:59 -0700
Update of /cvsroot/python/python/dist/src/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv1962/Lib
Modified Files:
_strptime.py
Log Message:
Make _strptime escape regex syntax in format string to prevent use in internal regex.
Index: _strptime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/_strptime.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** _strptime.py 9 Mar 2003 07:44:41 -0000 1.13
--- _strptime.py 19 Apr 2003 04:00:54 -0000 1.14
***************
*** 374,379 ****
def pattern(self, format):
! """Return re pattern for the format string."""
processed_format = ''
whitespace_replacement = re_compile('\s+')
format = whitespace_replacement.sub('\s*', format)
--- 374,388 ----
def pattern(self, format):
! """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)