fix: DCP_PAIRED_TAG_REGEX regex bug causes tag fragment leakage into chat#124
Closed
mengfanbo123 wants to merge 1 commit into
Closed
fix: DCP_PAIRED_TAG_REGEX regex bug causes tag fragment leakage into chat#124mengfanbo123 wants to merge 1 commit into
mengfanbo123 wants to merge 1 commit into
Conversation
line 14 正则 /]*>/ 开头匹配字面量 ']',缺少 '<' 和标签名。 导致 stripHallucinationsFromString 部分删除配对标签—— 删了闭标签+内容,残留开标签碎片(如 </d-message-id>)泄漏到用户对话框。 修复:正则改为 /<(?:dcp|acp)[^>]*>/ 正确匹配开标签。 Closes ranxianglei#123
Owner
|
缺少devlog和tests因此ci无法通过 |
Owner
|
Thanks for the fix! Your root cause analysis for While reviewing, I found that lines 11 ( Closing this in favor of #130. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
After multiple compression rounds, malformed XML tag fragments like
</d-message-id>and stale message IDs (e.g.m00097,m00099) leak into the user-visible chat dialog.Root Cause
lib/messages/utils.ts:14—DCP_PAIRED_TAG_REGEX:The buggy regex starts with
]*>which matches a literal]character — missing the<and tag name. As a result,stripHallucinationsFromStringonly partially deletes paired tags: it removes the closing tag + content but leaves behind opening-tag fragments that then leak into the chat.Call Path
stripHallucinations(lib/messages/utils.ts:265) → called globally atlib/hooks.ts:246.stripHallucinationsFromString(utils.ts:261) runs the PAIRED regex first (which misses due to the bug), then the UNPAIRED regex/<\/?(?:dcp|acp)[^>]*/gito clean up residual tag fragments.Fix
Add
<(?:dcp|acp)[^>]*>to correctly match the opening tag. Now the PAIRED regex matches the full open+content+close span and removes it in one pass.Verification
node --import tsx --test tests/strip-stale-compress.test.ts tests/inject.test.ts tests/message-utils.test.ts→ 32/32 passRelated
lib/messages/utils.ts:11DCP_BLOCK_ID_TAG_REGEX = /(])[^>]*>)b\d+(...)/ghas a similar]literal issue — suggest review in a follow-up.