fix: correct all 3 broken regexes causing tag fragment leak (issue #123)#130
Merged
Conversation
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.
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.
Summary
Fixes #123. Supersedes PR #124 (which fixed only 1 of 3 broken regexes).
Three regexes in
lib/messages/utils.tshad the same class of bug — missing<and tag name in opening tag match:DCP_PAIRED_TAG_REGEX]*>matched any>charstripHallucinationsFromStringleft tag fragments in chat (PR #124's fix)DCP_BLOCK_ID_TAG_REGEX(])required literal]replaceBlockIdsWithBlockedwas a no-op — never matched real tagsDCP_MESSAGE_REF_TAG_REGEXstripStaleMessageRefsleft<dcp-message-id ...>fragments in summariesChanges
lib/messages/utils.tstests/regex-tag-leak.test.ts(NEW — 23 tests)replaceBlockIdsWithBlocked: 7 testsstripStaleMessageRefs: 8 tests (including fragment-leak regression test)stripHallucinationsFromString: 8 tests (including issue [Bug]: stripHallucinations 正则错误导致 dcp-message-id 标签碎片泄漏到对话框 #123 regression test)Verification
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.