From c4e13ee7d20d3dd95b68254351aa50ea6e24a69a Mon Sep 17 00:00:00 2001 From: Nanin <7017924+nanin@users.noreply.github.com> Date: Wed, 5 Aug 2026 18:19:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E6=A1=A3=E6=A1=88=E6=90=9C=E7=B4=A2=E8=AF=AF=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=86=85=E9=83=A8=20ID?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除隐藏 senderId 搜索字段,避免 xi 等关键词误命中 wxid - 保留发送者昵称、消息正文及结构化可见内容的搜索能力 - 新增 wxid 与可见正文匹配的回归测试 --- src/main/export-html-template.ts | 1 - tests/unit/export-media.test.ts | 53 ++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/main/export-html-template.ts b/src/main/export-html-template.ts index 89e4977..233b0b5 100644 --- a/src/main/export-html-template.ts +++ b/src/main/export-html-template.ts @@ -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, diff --git a/tests/unit/export-media.test.ts b/tests/unit/export-media.test.ts index c45ead5..d399c44 100644 --- a/tests/unit/export-media.test.ts +++ b/tests/unit/export-media.test.ts @@ -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' })