mirror of
https://github.com/ihabunek/toot
synced 2024-12-23 07:27:12 +01:00
Added safeguards to prevent crashes when rendering corrupt URLs
This commit is contained in:
parent
e1be3a68bb
commit
20968fe87f
@ -60,7 +60,10 @@ def html_to_widgets(html, recovery_attempt=False) -> List[urwid.Widget]:
|
|||||||
|
|
||||||
|
|
||||||
def url_to_widget(url: str):
|
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)
|
return TextEmbed(widget)
|
||||||
|
|
||||||
|
|
||||||
@ -98,10 +101,16 @@ def text_to_widget(attr, markup) -> urwid.Widget:
|
|||||||
if match:
|
if match:
|
||||||
label, url = match.groups()
|
label, url = match.groups()
|
||||||
anchor_attr = get_best_anchor_attr(attr_list)
|
anchor_attr = get_best_anchor_attr(attr_list)
|
||||||
markup_list.append((
|
try:
|
||||||
len(label),
|
markup_list.append((
|
||||||
urwid.Filler(Hyperlink(url, anchor_attr, label)),
|
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:
|
else:
|
||||||
markup_list.append(run)
|
markup_list.append(run)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user