From 20401241476c30393df685027cf6b4fc540eb663 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Thu, 25 May 2023 02:41:56 +0900 Subject: [PATCH] Prevent dropping ellipsis URL (#585) --- core/html.py | 2 +- static/css/style.css | 6 +++++- tests/api/test_statuses.py | 20 ++++++++++++++++++++ tests/core/test_html.py | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/html.py b/core/html.py index 8ac3d7d..be5fa97 100644 --- a/core/html.py +++ b/core/html.py @@ -169,7 +169,7 @@ class FediverseHtmlParser(HTMLParser): if looks_like_link: content = content.split("://", 1)[1] if (looks_like_link and len(content) > 30) or has_ellipsis: - return f'{html.escape(content[:30])}' + return f'{html.escape(content[:30])}' else: return f'{html.escape(content)}' diff --git a/static/css/style.css b/static/css/style.css index 1ca8c42..09c4889 100644 --- a/static/css/style.css +++ b/static/css/style.css @@ -394,7 +394,7 @@ img.emoji { vertical-align: baseline; } -.ellipsis::after { +span.ellipsis::after { content: "…"; } @@ -1485,6 +1485,10 @@ form .post { margin: 12px 0 4px 0; } +.post .content p a .invisible { + display: none; +} + .post .attachments { padding-top: 4px; display: grid; diff --git a/tests/api/test_statuses.py b/tests/api/test_statuses.py index 3b763df..50d5ec3 100644 --- a/tests/api/test_statuses.py +++ b/tests/api/test_statuses.py @@ -155,3 +155,23 @@ def test_question_format(api_client, remote_identity): ], "emojis": [], } + + +@pytest.mark.django_db +def test_content_link(api_client, identity, remote_identity): + """ + Ensures mentions work, and only have one link around them. + """ + # Make a local post and check it + response = api_client.post( + "/api/v1/statuses", + data={ + "status": "Takahē - return to the wild - https://www.youtube.com/watch?v=IG423K3pmQI", + }, + ).json() + + # temp fix + assert ( + response["content"] + == '

Takahē - return to the wild - www.youtube.com/watch?v=IG423K

' + ) diff --git a/tests/core/test_html.py b/tests/core/test_html.py index 26d5f21..da3ff7a 100644 --- a/tests/core/test_html.py +++ b/tests/core/test_html.py @@ -54,7 +54,7 @@ def test_parser(identity): parser = FediverseHtmlParser(f"

{full_url}

") assert ( parser.html - == f'

social.example.com/a-long/path

' + == f'

social.example.com/a-long/path

' ) assert ( parser.plain_text