[Python-checkins] python/dist/src/Lib/test test_strptime.py,1.10,1.11

bcannon@users.sourceforge.net bcannon@users.sourceforge.net
Fri, 18 Apr 2003 21:00:59 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv1962/Lib/test

Modified Files:
	test_strptime.py 
Log Message:
Make _strptime escape regex syntax in format string to prevent use in internal regex.

Index: test_strptime.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_strptime.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** test_strptime.py	9 Mar 2003 07:44:42 -0000	1.10
--- test_strptime.py	19 Apr 2003 04:00:56 -0000	1.11
***************
*** 169,172 ****
--- 169,180 ----
                           pattern_string)
  
+     def test_pattern_escaping(self):
+         # Make sure any characters in the format string that might be taken as
+         # regex syntax is escaped.
+         pattern_string = self.time_re.pattern("\d+")
+         self.failUnless(r"\\d\+" in pattern_string,
+                         "%s does not have re characters escaped properly" %
+                         pattern_string)
+ 
      def test_compile(self):
          # Check that compiled regex is correct
***************
*** 201,204 ****
--- 209,218 ----
          self.failUnless(_strptime.TimeRE(test_locale).pattern("%Z") == '',
                          "with timezone == ('',''), TimeRE().pattern('%Z') != ''")
+ 
+     def test_matching_with_escapes(self):
+         # Make sure a format that requires escaping of characters works
+         compiled_re = self.time_re.compile("\w+ %m")
+         found = compiled_re.match("\w+ 10")
+         self.failUnless(found, "Escaping failed of format '\w+ 10'")
  
  class StrptimeTests(unittest.TestCase):