From 8fae9ff68bf1dc0e27a191220346438666b30312 Mon Sep 17 00:00:00 2001 From: Vincent Chan Date: Wed, 17 Jun 2026 14:32:28 +0800 Subject: [PATCH] Fix topic URL parsing to accept slug-form URLs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The regex only matched the `/t/topic/{id}` form, so standard Discourse share links that carry a slug (`/t/{slug}/{id}`) failed with "无法从URL中解析出主题ID". Broaden the pattern to `/t/(?:[^/]+/)?(\d+)(?:/\d+)?` so it accepts both the slug form and the existing `/t/topic/{id}` form. Strictly more permissive — no regression on the current case. Co-Authored-By: Claude Opus 4.8 (1M context) --- lottery.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lottery.py b/lottery.py index cd198a4..aed3201 100644 --- a/lottery.py +++ b/lottery.py @@ -45,7 +45,7 @@ def __init__(self, topic_id): @classmethod def from_url(cls, url): """从URL中解析主题信息""" - pattern = r"/t/topic/(\d+)(?:/\d+)?" + pattern = r"/t/(?:[^/]+/)?(\d+)(?:/\d+)?" match = re.search(pattern, url) if not match: raise ValidationError("无法从URL中解析出主题ID")