Skip to content

Commit

Permalink
Merge pull request #473 from danschwarz/corrupt_link_fix
Browse files Browse the repository at this point in the history
Added safeguards to prevent crashes when rendering corrupt URLs
  • Loading branch information
ihabunek authored Mar 12, 2024
2 parents 3bac9b2 + 20968fe commit 4b17e2e
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 4b17e2e

Please sign in to comment.