aboutsummaryrefslogtreecommitdiff
path: root/tests/tasks/test_receiver.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-30 19:34:42 +0100
committerDennis Fink2026-10-30 19:34:42 +0100
commit616ab6a8daaae6334b832fee12d9e8e335f0aba6 (patch)
tree946a1438559548c1074dd4b61b9bb64b5e0eedf8 /tests/tasks/test_receiver.py
parentdcbbfdb38d4e18e377d4e326d82f35341840c6cc (diff)
downloadwebmentions-ssg-616ab6a8daaae6334b832fee12d9e8e335f0aba6.tar.gz
webmentions-ssg-616ab6a8daaae6334b832fee12d9e8e335f0aba6.zip
fix(receiver): handle punctuation around plain-text URLs
Ignore surrounding prose punctuation when matching target IRIs in text/plain sources so valid Webmentions are not rejected when URLs appear in normal sentences. Preserve balanced URL parentheses and reject longer URLs that only share the target as a prefix.
Diffstat (limited to '')
-rw-r--r--tests/tasks/test_receiver.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/tasks/test_receiver.py b/tests/tasks/test_receiver.py
index 1943b65..6858be9 100644
--- a/tests/tasks/test_receiver.py
+++ b/tests/tasks/test_receiver.py
@@ -168,7 +168,33 @@ def test_html_mentions_relative_target(receiver: ModuleType) -> None:
TARGET_URL,
True,
),
+ pytest.param(
+ f"See {TARGET_URL}, thanks", TARGET_URL, True, id="trailing-comma"
+ ),
+ pytest.param(f"({TARGET_URL})", TARGET_URL, True, id="parenthesized-url"),
+ pytest.param(
+ f"See ({TARGET_URL}), thanks!", TARGET_URL, True, id="mixed-punctuation"
+ ),
+ pytest.param(f"See {TARGET_URL}. Next", TARGET_URL, True, id="trailing-period"),
+ pytest.param(
+ "https://example.com/wiki/Foo_(bar)",
+ "https://example.com/wiki/Foo_(bar)",
+ True,
+ id="balanced-parentheses-in-url",
+ ),
+ pytest.param(
+ "https://example.com/wiki/Foo_(bar)",
+ "https://example.com/wiki/Foo_(bar",
+ False,
+ id="balanced-parentheses-not-trimmed",
+ ),
(f"{TARGET_URL}more", TARGET_URL, False),
+ pytest.param(
+ f"{TARGET_URL},another-page",
+ TARGET_URL,
+ False,
+ id="comma-within-longer-url",
+ ),
("https://dennisfink.me/blog/other/", TARGET_URL, False),
("/blog/example/", TARGET_URL, False),
("There are no links here.", TARGET_URL, False),
@@ -339,6 +365,12 @@ def test_fetch_source_rejects_streamed_oversized_body(
id="plain-text-utf-8",
),
pytest.param(
+ "text/plain; charset=utf-8",
+ f"See ({TARGET_URL}), thanks".encode(),
+ True,
+ id="plain-text-with-surrounding-punctuation",
+ ),
+ pytest.param(
"text/plain; charset=iso-8859-1",
(f"Grüße. Reply to {TARGET_URL}").encode("iso-8859-1"),
True,