@@ -86,6 +86,17 @@ def test_truncate_chars(self):
8686 # lazy strings are handled correctly
8787 self .assertEqual (text .Truncator (lazystr ('The quick brown fox' )).chars (10 ), 'The quick…' )
8888
89+ def test_truncate_chars_html (self ):
90+ perf_test_values = [
91+ (('</a' + '\t ' * 50000 ) + '//>' , None ),
92+ ('&' * 50000 , '&' * 9 + '…' ),
93+ ('_X<<<<<<<<<<<>' , None ),
94+ ]
95+ for value , expected in perf_test_values :
96+ with self .subTest (value = value ):
97+ truncator = text .Truncator (value )
98+ self .assertEqual (expected if expected else value , truncator .chars (10 , html = True ))
99+
89100 def test_truncate_words (self ):
90101 truncator = text .Truncator ('The quick brown fox jumped over the lazy dog.' )
91102 self .assertEqual ('The quick brown fox jumped over the lazy dog.' , truncator .words (10 ))
@@ -135,11 +146,17 @@ def test_truncate_html_words(self):
135146 truncator = text .Truncator ('<i>Buenos días! ¿Cómo está?</i>' )
136147 self .assertEqual ('<i>Buenos días! ¿Cómo…</i>' , truncator .words (3 , html = True ))
137148 truncator = text .Truncator ('<p>I <3 python, what about you?</p>' )
138- self .assertEqual ('<p>I <3 python…</p>' , truncator .words (3 , html = True ))
149+ self .assertEqual ('<p>I <3 python, …</p>' , truncator .words (3 , html = True ))
139150
140- re_tag_catastrophic_test = ('</a' + '\t ' * 50000 ) + '//>'
141- truncator = text .Truncator (re_tag_catastrophic_test )
142- self .assertEqual (re_tag_catastrophic_test , truncator .words (500 , html = True ))
151+ perf_test_values = [
152+ ('</a' + '\t ' * 50000 ) + '//>' ,
153+ '&' * 50000 ,
154+ '_X<<<<<<<<<<<>' ,
155+ ]
156+ for value in perf_test_values :
157+ with self .subTest (value = value ):
158+ truncator = text .Truncator (value )
159+ self .assertEqual (value , truncator .words (50 , html = True ))
143160
144161 def test_wrap (self ):
145162 digits = '1234 67 9'
0 commit comments