diff --git a/core/html.py b/core/html.py index be5fa97..68d66ff 100644 --- a/core/html.py +++ b/core/html.py @@ -167,9 +167,13 @@ class FediverseHtmlParser(HTMLParser): """ looks_like_link = bool(self.URL_REGEX.match(content)) if looks_like_link: - content = content.split("://", 1)[1] + protocol, content = content.split("://", 1) + else: + protocol = "" if (looks_like_link and len(content) > 30) or has_ellipsis: - return f'{html.escape(content[:30])}{html.escape(content[30:])}' + return f'{html.escape(protocol)}://{html.escape(content[:30])}{html.escape(content[30:])}' + elif looks_like_link: + return f'{html.escape(protocol)}://{html.escape(content)}' else: return f'{html.escape(content)}' diff --git a/tests/api/test_statuses.py b/tests/api/test_statuses.py index 50d5ec3..f6ef0e7 100644 --- a/tests/api/test_statuses.py +++ b/tests/api/test_statuses.py @@ -170,8 +170,7 @@ def test_content_link(api_client, identity, remote_identity): }, ).json() - # temp fix assert ( response["content"] - == '
Takahē - return to the wild - www.youtube.com/watch?v=IG423K3pmQI
' + == 'Takahē - return to the wild - https://www.youtube.com/watch?v=IG423K3pmQI
' ) diff --git a/tests/core/test_html.py b/tests/core/test_html.py index da3ff7a..09f8032 100644 --- a/tests/core/test_html.py +++ b/tests/core/test_html.py @@ -37,7 +37,8 @@ def test_parser(identity): assert parser.plain_text == "test.com" parser = FediverseHtmlParser("https://test.com
") assert ( - parser.html == '' + parser.html + == '' ) assert parser.plain_text == "https://test.com" @@ -54,7 +55,7 @@ def test_parser(identity): parser = FediverseHtmlParser(f"{full_url}
") assert ( parser.html - == f'social.example.com/a-long/path/that-should-be-shortened
' + == f'https://social.example.com/a-long/path/that-should-be-shortened
' ) assert ( parser.plain_text