|
|
28b261 |
diff --git a/Lib/difflib.py b/Lib/difflib.py
|
|
|
28b261 |
index 1c6fbdbedcb7..788a92df3f89 100644
|
|
|
28b261 |
--- a/Lib/difflib.py
|
|
|
28b261 |
+++ b/Lib/difflib.py
|
|
|
28b261 |
@@ -1103,7 +1103,7 @@ def _qformat(self, aline, bline, atags, btags):
|
|
|
28b261 |
|
|
|
28b261 |
import re
|
|
|
28b261 |
|
|
|
28b261 |
-def IS_LINE_JUNK(line, pat=re.compile(r"\s*#?\s*$").match):
|
|
|
28b261 |
+def IS_LINE_JUNK(line, pat=re.compile(r"\s*(?:#\s*)?$").match):
|
|
|
28b261 |
r"""
|
|
|
28b261 |
Return 1 for ignorable line: iff `line` is blank or contains a single '#'.
|
|
|
28b261 |
|
|
|
28b261 |
diff --git a/Lib/poplib.py b/Lib/poplib.py
|
|
|
28b261 |
index b91e5f72d2ca..a238510b38fc 100644
|
|
|
28b261 |
--- a/Lib/poplib.py
|
|
|
28b261 |
+++ b/Lib/poplib.py
|
|
|
28b261 |
@@ -274,7 +274,7 @@ def rpop(self, user):
|
|
|
28b261 |
return self._shortcmd('RPOP %s' % user)
|
|
|
28b261 |
|
|
|
28b261 |
|
|
|
28b261 |
- timestamp = re.compile(r'\+OK.*(<[^>]+>)')
|
|
|
28b261 |
+ timestamp = re.compile(br'\+OK.[^<]*(<.*>)')
|
|
|
28b261 |
|
|
|
28b261 |
def apop(self, user, secret):
|
|
|
28b261 |
"""Authorisation
|
|
|
28b261 |
diff --git a/Lib/test/test_difflib.py b/Lib/test/test_difflib.py
|
|
|
28b261 |
index 35f2c36ca70a..d8277b79b880 100644
|
|
|
28b261 |
--- a/Lib/test/test_difflib.py
|
|
|
28b261 |
+++ b/Lib/test/test_difflib.py
|
|
|
28b261 |
@@ -269,13 +269,33 @@ def test_range_format_context(self):
|
|
|
28b261 |
self.assertEqual(fmt(3,6), '4,6')
|
|
|
28b261 |
self.assertEqual(fmt(0,0), '0')
|
|
|
28b261 |
|
|
|
28b261 |
+class TestJunkAPIs(unittest.TestCase):
|
|
|
28b261 |
+ def test_is_line_junk_true(self):
|
|
|
28b261 |
+ for line in ['#', ' ', ' #', '# ', ' # ', '']:
|
|
|
28b261 |
+ self.assertTrue(difflib.IS_LINE_JUNK(line), repr(line))
|
|
|
28b261 |
+
|
|
|
28b261 |
+ def test_is_line_junk_false(self):
|
|
|
28b261 |
+ for line in ['##', ' ##', '## ', 'abc ', 'abc #', 'Mr. Moose is up!']:
|
|
|
28b261 |
+ self.assertFalse(difflib.IS_LINE_JUNK(line), repr(line))
|
|
|
28b261 |
+
|
|
|
28b261 |
+ def test_is_line_junk_REDOS(self):
|
|
|
28b261 |
+ evil_input = ('\t' * 1000000) + '##'
|
|
|
28b261 |
+ self.assertFalse(difflib.IS_LINE_JUNK(evil_input))
|
|
|
28b261 |
+
|
|
|
28b261 |
+ def test_is_character_junk_true(self):
|
|
|
28b261 |
+ for char in [' ', '\t']:
|
|
|
28b261 |
+ self.assertTrue(difflib.IS_CHARACTER_JUNK(char), repr(char))
|
|
|
28b261 |
+
|
|
|
28b261 |
+ def test_is_character_junk_false(self):
|
|
|
28b261 |
+ for char in ['a', '#', '\n', '\f', '\r', '\v']:
|
|
|
28b261 |
+ self.assertFalse(difflib.IS_CHARACTER_JUNK(char), repr(char))
|
|
|
28b261 |
|
|
|
28b261 |
def test_main():
|
|
|
28b261 |
difflib.HtmlDiff._default_prefix = 0
|
|
|
28b261 |
Doctests = doctest.DocTestSuite(difflib)
|
|
|
28b261 |
run_unittest(
|
|
|
28b261 |
TestWithAscii, TestAutojunk, TestSFpatches, TestSFbugs,
|
|
|
28b261 |
- TestOutputFormat, Doctests)
|
|
|
28b261 |
+ TestOutputFormat, TestJunkAPIs)
|
|
|
28b261 |
|
|
|
28b261 |
if __name__ == '__main__':
|
|
|
28b261 |
test_main()
|
|
|
28b261 |
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
|
|
|
28b261 |
index 23d688724b95..d2143759ba66 100644
|
|
|
28b261 |
--- a/Lib/test/test_poplib.py
|
|
|
28b261 |
+++ b/Lib/test/test_poplib.py
|
|
|
28b261 |
@@ -211,6 +211,16 @@ def test_noop(self):
|
|
|
28b261 |
def test_rpop(self):
|
|
|
28b261 |
self.assertOK(self.client.rpop('foo'))
|
|
|
28b261 |
|
|
|
28b261 |
+ def test_apop_REDOS(self):
|
|
|
28b261 |
+ # Replace welcome with very long evil welcome.
|
|
|
28b261 |
+ # NB The upper bound on welcome length is currently 2048.
|
|
|
28b261 |
+ # At this length, evil input makes each apop call take
|
|
|
28b261 |
+ # on the order of milliseconds instead of microseconds.
|
|
|
28b261 |
+ evil_welcome = b'+OK' + (b'<' * 1000000)
|
|
|
28b261 |
+ with test_support.swap_attr(self.client, 'welcome', evil_welcome):
|
|
|
28b261 |
+ # The evil welcome is invalid, so apop should throw.
|
|
|
28b261 |
+ self.assertRaises(poplib.error_proto, self.client.apop, 'a', 'kb')
|
|
|
28b261 |
+
|
|
|
28b261 |
def test_top(self):
|
|
|
28b261 |
expected = ('+OK 116 bytes',
|
|
|
28b261 |
['From: postmaster@python.org', 'Content-Type: text/plain',
|