fix: 修复聊天档案搜索误匹配微信内部 ID

- 移除隐藏 senderId 搜索字段,避免 xi 等关键词误命中 wxid
- 保留发送者昵称、消息正文及结构化可见内容的搜索能力
- 新增 wxid 与可见正文匹配的回归测试
This commit is contained in:
Nanin
2026-08-05 18:19:55 +08:00
parent 12cae061df
commit c4e13ee7d2
2 changed files with 53 additions and 1 deletions
-1
View File
@@ -940,7 +940,6 @@ const renderExportScript = (name: string): string => `
const searchText = (message) => [
message.exportConversationName,
message.name,
message.senderId,
message.content,
message.type,
message.contentData && message.contentData.title,
+53
View File
@@ -106,6 +106,59 @@ describe('export media', () => {
dom.window.close()
})
it('does not match hidden sender ids when searching visible message text', () => {
const html = renderExportPage('搜索测试')
const dom = new JSDOM(html, { runScripts: 'outside-only' })
const messages: Message[] = [
{
id: 'hidden-sender-id-match',
from: 'user',
type: '普通文本',
datetime: '',
content: '这条消息不应命中',
name: 'Jamie',
senderId: 'wxid_fixture_member',
isSender: false,
createTime: 1_767_225_600
},
{
id: 'visible-content-match',
from: 'user',
type: '普通文本',
datetime: '',
content: 'https://example.com/xi',
name: 'Cherry',
senderId: 'wxid_fixture_self',
isSender: true,
createTime: 1_767_225_601
}
]
Object.assign(dom.window, {
__WECHAT_EXPORT__: {
version: 1,
sourceId: 'fixture',
name: '搜索测试',
exportedAt: '2026-08-05T00:00:00.000Z',
messages
}
})
dom.window.eval(inlineScriptOf(html))
const search = dom.window.document.querySelector('#query') as HTMLInputElement
search.value = 'xi'
search.dispatchEvent(new dom.window.Event('input'))
expect(dom.window.document.querySelectorAll('.message')).toHaveLength(1)
expect(dom.window.document.querySelector('.message')?.textContent).toContain(
'https://example.com/xi'
)
expect(dom.window.document.querySelectorAll('.search-highlight')).toHaveLength(1)
expect(dom.window.document.querySelector('#count')?.textContent).toBe(
'已显示 1 / 筛选 1 / 全部 2'
)
dom.window.close()
})
it('filters a v2 merged archive by conversation before search and month counts', () => {
const html = renderExportPage('合并档案')
const dom = new JSDOM(html, { runScripts: 'outside-only' })