Peach: Local-first video metadata scraper and media manager.
fix(tooling): 社交域名匹配落在点边界上
longmeidaod413a0fd09a9
diff --git a/scripts/import_stash_entities.py b/scripts/import_stash_entities.pyindex adee36288..dabe09f12 100644--- a/scripts/import_stash_entities.py+++ b/scripts/import_stash_entities.py@@ -33,9 +33,21 @@ def normalized(value: str) -> str:return " ".join(value.casefold().split())+SOCIAL_HOSTS = ("x.com", "twitter.com", "instagram.com", "youtube.com", "tiktok.com")+++def under(host: str, domains: tuple[str, ...]) -> bool:+ """host 是否就是这些域名之一或它们的子域。++ 直接用 `endswith` 会把 `notx.com` 判成 x.com——后缀匹配必须落在点边界上,+ 否则任何人注册一个以平台名结尾的域名就能让链接在资料页上显示成官方社交账号。+ """+ return any(host == domain or host.endswith("." + domain) for domain in domains)++def link_kind(url: str) -> str:host = (urlsplit(url).hostname or "").casefold()- if host.endswith(("x.com", "twitter.com", "instagram.com", "youtube.com", "tiktok.com")):+ if under(host, SOCIAL_HOSTS):return "social"return "catalog"diff --git a/tests/test_stash_entity_import.py b/tests/test_stash_entity_import.pyindex 18b8df466..854d5407f 100644--- a/tests/test_stash_entity_import.py+++ b/tests/test_stash_entity_import.py@@ -63,6 +63,19 @@ class StashEntityImportTests(unittest.TestCase):).fetchone()[0]self.assertIn("Performer summary", metadata)+ def test_social_host_match_lands_on_dot_boundary(self):+ """后缀匹配必须落在点边界上。++ `"notx.com".endswith("x.com")` 为真,旧写法会把任何以平台名结尾的域名判成 social,+ 写进 entity_link 后在资料页上显示成官方社交账号。+ """+ for url in ("https://x.com/alice", "https://mobile.twitter.com/alice",+ "https://www.instagram.com/alice"):+ self.assertEqual(MODULE.link_kind(url), "social", url)+ for url in ("https://notx.com/alice", "https://faketwitter.com/alice",+ "https://example.com/alice"):+ self.assertEqual(MODULE.link_kind(url), "catalog", url)+def test_reads_png_and_jpeg_dimensions(self):png_buffer = io.BytesIO()jpeg_buffer = io.BytesIO()