File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -99,6 +99,8 @@ def set_terminator(self, term):
9999 """
100100 if isinstance (term , str ) and self .use_encoding :
101101 term = bytes (term , self .encoding )
102+ elif isinstance (term , int ) and term < 0 :
103+ raise ValueError ('the number of received bytes must be positive' )
102104 self .terminator = term
103105
104106 def get_terminator (self ):
Original file line number Diff line number Diff line change @@ -304,5 +304,13 @@ def test_given_list(self):
304304 self .assertEqual (f .pop (), (0 , None ))
305305
306306
307+ class TestNotConnected (unittest .TestCase ):
308+ def test_disallow_negative_terminator (self ):
309+ # Issue #11259
310+ client = asynchat .async_chat ()
311+ self .assertRaises (ValueError , client .set_terminator , - 1 )
312+
313+
314+
307315if __name__ == "__main__" :
308316 unittest .main ()
Original file line number Diff line number Diff line change @@ -27,6 +27,9 @@ Core and Builtins
2727Library
2828-------
2929
30+ - Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError
31+ if the number of received bytes is negative.
32+
3033- Issue #12523: asynchat.async_chat.push() now raises a TypeError if it doesn't
3134 get a bytes string
3235
You can’t perform that action at this time.
0 commit comments