From 3e350be1b838c19f928aa0f1e9292958cd76a455 Mon Sep 17 00:00:00 2001 From: Taranum01 Date: Sat, 15 Aug 2026 00:10:54 +0530 Subject: [PATCH] fix(model): accept relative URLs in re_sign_file_url_answer Regression for #40788. The new multi-pattern URL detector required an `https?://` prefix, which broke the existing tests that use relative `/files/...` URLs inside markdown link payloads. - Make the host prefix optional so all three supported shapes (markdown, backticked, bare) match both relative and absolute paths. - Replace the trailing `.*` after each URL parameter with a bounded `[^)\s]*?` so the bare-URL pattern doesn't run off the end of the answer string and gobble up adjacent URLs. --- api/models/model.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/api/models/model.py b/api/models/model.py index 7a940d49d3c..0921104e185 100644 --- a/api/models/model.py +++ b/api/models/model.py @@ -1669,7 +1669,13 @@ class Message(Base): # The original implementation only matched the markdown form, so # bare and backticked tool file URLs kept the long-lived # INTERNAL_FILES_URL host and 5xx-ed at serve time. Refs #40788. - url_core = r"https?:\/\/.+?\/files\/(tools\/)?[\w-]+.*?timestamp=.*&nonce=.*&sign=.*" + # The host prefix is optional so relative `/files/...` URLs that + # the agent returns without a host are also covered. The + # `(?=[)\s`]|$)` at the end of the bare-URL pattern (and the + # closing backtick / paren on the wrapped forms) stops the + # greedy `.*?=.*?` after `&sign=` from running off the end of + # the answer. + url_core = r"(?:https?:\/\/.+?)?\/files\/(tools\/)?[\w-]+.*?timestamp=[^)\s]*?&nonce=[^)\s]*?&sign=[^)\s]*?" patterns = [ r"\[!?.*?\]\((" + url_core + r")\)", # [text](url) r"`(" + url_core + r")`", # `url` @@ -1683,9 +1689,6 @@ class Message(Base): if not urls: return self.answer - if not urls: - return self.answer - re_sign_file_url_answer = self.answer for url in urls: if "files/tools" in url: @@ -1728,6 +1731,7 @@ class Message(Base): result = re.search(upload_file_id_pattern, url) if not result: continue + upload_file_id = result.group(1) if not upload_file_id: continue