Skip to content

Conversation

@HarryReidx
Copy link

@HarryReidx HarryReidx commented Nov 21, 2025

The utility function remove_leading_symbols was incorrectly stripping the leading exclamation mark from Markdown image syntax ![](). This change adjusts the regex to preserve the !, allowing images to render properly. ---
修复知识库图片无法显示的 Bug

remove_leading_symbols 工具函数错误地去除了 Markdown 图像语法 ![]() 开头的感叹号。本次更改调整了正则表达式,以保留 ![] 结构,使图片能够正确渲染。

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

Screenshots

| Before | After |
| image |
image |

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods

The utility function `remove_leading_symbols` was incorrectly stripping the leading exclamation mark from Markdown image syntax `![]()`. This change adjusts the regex to preserve the `!`, allowing images to render properly.
---
修复知识库图片无法显示的 Bug

`remove_leading_symbols` 工具函数错误地去除了 Markdown 图像语法 `![]()` 开头的感叹号。本次更改调整了正则表达式,以保留 `![]` 结构,使图片能够正确渲染。
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @HarryReidx, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在解决知识库中图片无法正常显示的问题。通过调整一个文本处理工具函数中的正则表达式,确保 Markdown 图像语法中的关键字符 ! 不再被错误地移除,从而恢复了图片的正确渲染。

Highlights

  • 修复知识库图片显示问题: 修正了 remove_leading_symbols 工具函数中的正则表达式,以防止其错误地移除 Markdown 图像语法 ![]() 中的前导感叹号,确保知识库中的图片能够正常显示。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Nov 21, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request aims to fix an issue where Markdown images fail to display by adjusting the regex that removes leading symbols. The current change correctly prevents the ! from being stripped from image links. However, this fix is too broad and introduces a regression: it stops removing leading exclamation marks in all contexts, which will cause existing unit tests to fail. I have suggested a more precise fix using a negative lookahead in the regex to only preserve the ! when it's part of a Markdown image syntax. I also noted that the new tests mentioned in the PR description appear to be missing from the commit.

Comment on lines +14 to +16
# 移除了感叹号 '!' 原逻辑会错误地将 Markdown 图像语法 ![]() 中的前导 ![' 符号移除,导致输出的 Markdown 格式不完整,图片无法正常显示
# Removed the exclamation mark '!' The original logic would mistakenly remove the leading '!' symbol in the Markdown image syntax ![](), resulting in incomplete Markdown formatting and images that cannot be displayed properly.
pattern = r"^[\u2000-\u206F\u2E00-\u2E7F\u3000-\u303F\"#$%&'()*+,./:;<=>?@^_`~]+"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This change introduces a regression. By removing ! from the character set entirely, it prevents stripping of leading exclamation marks in all cases. This will cause the existing unit test with input "!@#Test symbols" to fail, as it expects all leading symbols to be removed.

A better approach is to use a negative lookahead to prevent stripping ! only when it's followed by [, which indicates Markdown image syntax. This fixes the bug without breaking existing behavior.

I've provided a code suggestion with an improved regex and a comment explaining the logic.

Also, please remember to include the new test cases for this fix in your commit, as mentioned in the PR description. A test case like ("![image](url)", "![image](url)") would be a good addition to prevent future regressions.

Suggested change
# 移除了感叹号 '!' 原逻辑会错误地将 Markdown 图像语法 ![]() 中的前导 ![' 符号移除,导致输出的 Markdown 格式不完整,图片无法正常显示
# Removed the exclamation mark '!' The original logic would mistakenly remove the leading '!' symbol in the Markdown image syntax ![](), resulting in incomplete Markdown formatting and images that cannot be displayed properly.
pattern = r"^[\u2000-\u206F\u2E00-\u2E7F\u3000-\u303F\"#$%&'()*+,./:;<=>?@^_`~]+"
# This pattern uses a negative lookahead `!(?!\)` to match an exclamation mark
# only if it's not followed by an opening square bracket. This prevents
# stripping the '!' from Markdown image links like '![...](...)' while
# still removing other leading symbols.
pattern = r"^([\u2000-\u206F\u2E00-\u2E7F\u3000-\u303F\"#$%&'()*+,./:;<=>?@^_`~]|!(?!\[]))+"

@crazywoola crazywoola changed the title Fix bug where knowledge base images fail to display | 修复知识库图片无法显示的bug Fix bug where knowledge base images fail to display Nov 21, 2025
@crazywoola
Copy link
Member

Thanks for the PR :)

  • Please link an existing issue or create a new issue and link it in the description.
  • Please add some tests for the changes as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants