Skip to content

Commit

Permalink
Added safeguards to prevent crashes when rendering corrupt URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
danschwarz committed Mar 9, 2024
1 parent e1be3a6 commit 20968fe
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions toot/tui/richtext/richtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def html_to_widgets(html, recovery_attempt=False) -> List[urwid.Widget]:


def url_to_widget(url: str):
widget = len(url), urwid.Filler(Hyperlink(url, "link", url))
try:
widget = len(url), urwid.Filler(Hyperlink(url, "link", url))
except ValueError:
widget = len(url), urwid.Filler(urwid.Text(url)) # don't style as link
return TextEmbed(widget)


Expand Down Expand Up @@ -98,10 +101,16 @@ def text_to_widget(attr, markup) -> urwid.Widget:
if match:
label, url = match.groups()
anchor_attr = get_best_anchor_attr(attr_list)
markup_list.append((
len(label),
urwid.Filler(Hyperlink(url, anchor_attr, label)),
))
try:
markup_list.append((
len(label),
urwid.Filler(Hyperlink(url, anchor_attr, label)),
))
except ValueError:
markup_list.append((
len(label),
urwid.Filler(urwid.Text(url)), # don't style as link
))
else:
markup_list.append(run)
else:
Expand Down

0 comments on commit 20968fe

Please sign in to comment.