File tree Expand file tree Collapse file tree 2 files changed +14
-5
lines changed
Expand file tree Collapse file tree 2 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -233,10 +233,11 @@ def recursive(entity_i: int) -> int:
233233 while i < len (entities ):
234234 i += recursive (i )
235235
236- last_offset = entities_offsets [- 1 ][1 ]
237- # no need to sort, but still add entities starting from the end
238- for entity , offset in reversed (entities_offsets ):
239- text = text [:offset ] + entity + html .escape (text [offset :last_offset ]) + text [last_offset :]
240- last_offset = offset
236+ if entities_offsets :
237+ last_offset = entities_offsets [- 1 ][1 ]
238+ # no need to sort, but still add entities starting from the end
239+ for entity , offset in reversed (entities_offsets ):
240+ text = text [:offset ] + entity + html .escape (text [offset :last_offset ]) + text [last_offset :]
241+ last_offset = offset
241242
242243 return utils .remove_surrogates (text )
Original file line number Diff line number Diff line change @@ -137,3 +137,11 @@ def test_html_unparse_escaped_nested():
137137 pyrogram .types .MessageEntity (type = pyrogram .enums .MessageEntityType .UNDERLINE , offset = 8 , length = 16 )])
138138
139139 assert HTML .unparse (text = text , entities = entities ) == expected
140+
141+
142+ def test_html_unparse_no_entities ():
143+ expected = "text"
144+ text = "text"
145+ entities = []
146+
147+ assert HTML .unparse (text = text , entities = entities ) == expected
You can’t perform that action at this time.
0 commit comments