Skip to content

fix: correct all 3 broken regexes causing tag fragment leak (issue #123)#130

Merged
ranxianglei merged 1 commit into
masterfrom
2026-07-14_fix-regex-tag-leak
Jul 14, 2026
Merged

fix: correct all 3 broken regexes causing tag fragment leak (issue #123)#130
ranxianglei merged 1 commit into
masterfrom
2026-07-14_fix-regex-tag-leak

Conversation

@ranxianglei

Copy link
Copy Markdown
Owner

Summary

Fixes #123. Supersedes PR #124 (which fixed only 1 of 3 broken regexes).

Three regexes in lib/messages/utils.ts had the same class of bug — missing < and tag name in opening tag match:

Line Regex Bug Impact
14 DCP_PAIRED_TAG_REGEX ]*> matched any > char stripHallucinationsFromString left tag fragments in chat (PR #124's fix)
11 DCP_BLOCK_ID_TAG_REGEX (]) required literal ] replaceBlockIdsWithBlocked was a no-op — never matched real tags
13 DCP_MESSAGE_REF_TAG_REGEX Missing opening tag stripStaleMessageRefs left <dcp-message-id ...> fragments in summaries

Changes

lib/messages/utils.ts

- const DCP_BLOCK_ID_TAG_REGEX = /(])[^>]*>)b\d+(<\/(?:dcp|acp)-message-id>)/g
+ const DCP_BLOCK_ID_TAG_REGEX = /(<(?:dcp|acp)-message-id[^>]*>)b\d+(<\/(?:dcp|acp)-message-id>)/g

- const DCP_MESSAGE_REF_TAG_REGEX = /m\d+<\/(?:dcp|acp)-message-id>/g
+ const DCP_MESSAGE_REF_TAG_REGEX = /<(?:dcp|acp)-message-id[^>]*>m\d+<\/(?:dcp|acp)-message-id>/g

- const DCP_PAIRED_TAG_REGEX = /]*>[\s\S]*?<\/(?:dcp|acp)[^>]*>/gi
+ const DCP_PAIRED_TAG_REGEX = /<(?:dcp|acp)[^>]*>[\s\S]*?<\/(?:dcp|acp)[^>]*>/gi

tests/regex-tag-leak.test.ts (NEW — 23 tests)

Verification

  • ✅ TypeScript: pass
  • ✅ Tests: 666 pass, 0 fail (643 existing + 23 new)
  • ✅ CI check: All passed

Relationship to PR #124

PR #124 by @mengfanbo123 correctly identified and fixed DCP_PAIRED_TAG_REGEX (line 14). However, the same class of bug existed on lines 11 and 13. This PR includes PR #124's fix plus the two additional fixes.

Credits: @mengfanbo123 for the initial root cause analysis in PR #124.

DCP_PAIRED_TAG_REGEX (line 14): ']*>' matched any '>' instead of
'<dcp...>' opening tags — partial deletion left tag fragments in chat.
Fix: '<(?:dcp|acp)[^>]*>' (same as PR #124).

DCP_BLOCK_ID_TAG_REGEX (line 11): '(])' required literal ']' char,
never matched real message-id tags — replaceBlockIdsWithBlocked was
a no-op. Fix: '(<(?:dcp|acp)-message-id[^>]*>)'.

DCP_MESSAGE_REF_TAG_REGEX (line 13): matched 'm\d+</closing>' only,
left '<dcp-message-id ...>' opening tag fragments in summaries.
Fix: added '<(?:dcp|acp)-message-id[^>]*>' prefix.

Tests: tests/regex-tag-leak.test.ts (NEW, 23 tests).
Closes #123. Supersedes PR #124.
@ranxianglei ranxianglei merged commit e666031 into master Jul 14, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: stripHallucinations 正则错误导致 dcp-message-id 标签碎片泄漏到对话框

1 participant