-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Fix bug where knowledge base images fail to display #28502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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 图像语法 `![]()` 开头的感叹号。本次更改调整了正则表达式,以保留 `![]` 结构,使图片能够正确渲染。
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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.
| # 移除了感叹号 '!' 原逻辑会错误地将 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\"#$%&'()*+,./:;<=>?@^_`~]+" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 ("", "") would be a good addition to prevent future regressions.
| # 移除了感叹号 '!' 原逻辑会错误地将 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\"#$%&'()*+,./:;<=>?@^_`~]|!(?!\[]))+" |
|
Thanks for the PR :)
|
The utility function
remove_leading_symbolswas 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
Fixes #<issue number>.Summary
Screenshots
| Before | After |
|
|
|
Checklist
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods