Code Block Distorts Content in WebApp (e.g., Regex Expressions) #12000

Closed
opened 2026-02-21 19:05:12 -05:00 by yindo · 1 comment
Owner

Originally created by @XiaoLey on GitHub (Mar 23, 2025).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.1.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I have encountered a bug in the Dify WebApp where certain content, like specific regex expressions, becomes distorted when wrapped in a code block. Some characters are altered, which makes the content different from the original. For example, I noticed this with the following regex: ^\(server.*\)/[^/]*$.

When placed inside a code block, some characters are either misinterpreted or replaced. This behavior affects the accuracy of the content, which is crucial for code snippets or technical information.

Steps to Reproduce:

  1. Compose a prompt to include the regex ^\(server.*\)/[^/]*$ inside a code block.
  2. Send this prompt through the WebApp to a model.
  3. Review the rendered content in the code block either in the WebApp output or the model's response.
  4. Notice that the content has been altered from the original.

Image

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @XiaoLey on GitHub (Mar 23, 2025). ### Self Checks - [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.1.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I have encountered a bug in the Dify WebApp where certain content, like specific regex expressions, becomes distorted when wrapped in a code block. Some characters are altered, which makes the content different from the original. For example, I noticed this with the following regex: `^\(server.*\)/[^/]*$`. When placed inside a code block, some characters are either misinterpreted or replaced. This behavior affects the accuracy of the content, which is crucial for code snippets or technical information. **Steps to Reproduce**: 1. Compose a prompt to include the regex `^\(server.*\)/[^/]*$` inside a code block. 2. Send this prompt through the WebApp to a model. 3. Review the rendered content in the code block either in the WebApp output or the model's response. 4. Notice that the content has been altered from the original. ![Image](https://github.com/user-attachments/assets/6bfa1c3a-2594-418f-a4b7-7cdcc6280aef) ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 buggood first issue labels 2026-02-21 19:05:12 -05:00
yindo closed this issue 2026-02-21 19:05:12 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 23, 2025):

The issue you're experiencing with regex expressions being distorted in code blocks might be related to how the Dify WebApp handles the rendering of code blocks. The CodeBlock component is responsible for rendering code blocks in the UI, and it includes a header with the language name and action buttons like a copy button. The code content is rendered within a div element [1].

If special characters in regex expressions are being altered, it could be due to how these characters are processed or escaped before rendering. Unfortunately, there isn't specific information available about how Dify handles escaping or encoding of special characters within code blocks, or any known issues related to this [1].

To address this, you might want to check if there are any configurations or settings in your environment that could affect the display of special characters. Additionally, reviewing the preprocessThinkTag function, which is responsible for rendering markdown content, might provide insights into how content is processed before rendering [2].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@dosubot[bot] commented on GitHub (Mar 23, 2025): <!-- Answer --> The issue you're experiencing with regex expressions being distorted in code blocks might be related to how the Dify WebApp handles the rendering of code blocks. The `CodeBlock` component is responsible for rendering code blocks in the UI, and it includes a header with the language name and action buttons like a copy button. The code content is rendered within a `div` element <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/base/markdown.tsx)</sup>. If special characters in regex expressions are being altered, it could be due to how these characters are processed or escaped before rendering. Unfortunately, there isn't specific information available about how Dify handles escaping or encoding of special characters within code blocks, or any known issues related to this <sup>[[1]](https://github.com/langgenius/dify/blob/main/web/app/components/base/markdown.tsx)</sup>. To address this, you might want to check if there are any configurations or settings in your environment that could affect the display of special characters. Additionally, reviewing the `preprocessThinkTag` function, which is responsible for rendering markdown content, might provide insights into how content is processed before rendering <sup>[[2]](https://github.com/langgenius/dify/issues/14594)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.* --- <sup>Help Dosu learn! Give it feedback: [Great Response](https://app.dosu.dev/response-feedback/86ee4da2-a766-458a-a808-75956cf0a2a3?feedback_type=great_response) | [Irrelevant Answer](https://app.dosu.dev/response-feedback/86ee4da2-a766-458a-a808-75956cf0a2a3?feedback_type=irrelevant_answer) | [Incorrect Sources](https://app.dosu.dev/response-feedback/86ee4da2-a766-458a-a808-75956cf0a2a3?feedback_type=incorrect_sources) | [Too Verbose](https://app.dosu.dev/response-feedback/86ee4da2-a766-458a-a808-75956cf0a2a3?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/86ee4da2-a766-458a-a808-75956cf0a2a3?feedback_type=hallucination) | [Bug Report](https://app.dosu.dev/response-feedback/86ee4da2-a766-458a-a808-75956cf0a2a3?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/86ee4da2-a766-458a-a808-75956cf0a2a3?feedback_type=other)</sup>
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#12000