summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_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/test/test_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/test/test_strptime.py')
-rw-r--r--Lib/test/test_strptime.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_strptime.py b/Lib/test/test_strptime.py
index e708f4c..a106a42 100644
--- a/Lib/test/test_strptime.py
+++ b/Lib/test/test_strptime.py
@@ -168,6 +168,14 @@ class TimeRETests(unittest.TestCase):
"did not find 'd' directive pattern string '%s'" %
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
found = self.time_re.compile(r"%A").match(self.locale_time.f_weekday[6])
@@ -201,6 +209,12 @@ class TimeRETests(unittest.TestCase):
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):
"""Tests for _strptime.strptime."""