mirror of
https://github.com/langgenius/dify.git
synced 2026-09-08 02:43:49 +08:00
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.
This commit is contained in:
parent
4f1841d763
commit
3e350be1b8
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user