From 1545253c1404486a7d90dd159c46c6b78f089db9 Mon Sep 17 00:00:00 2001 From: xiepengfei Date: Mon, 16 Nov 2026 22:45:52 +0800 Subject: [PATCH] fix: filter NUL bytes from input method events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: inputMethodEvent received commitString/preeditString from input methods without filtering NUL bytes (\x00), which were written into the document via insertSelectTextEx and persisted to file on save 2. Fix: remove NUL bytes from the text string before passing it to insertSelectTextEx, and skip insertion entirely if text becomes empty after removal 3. Impact: only affects text containing NUL bytes (e.g. from Sogou soft keyboard); normal text input is unaffected Influence: 1. Test input method commit with normal text to verify no regression 2. Test input method commit with NUL-containing text to verify NUL bytes are filtered 3. Test file save and reopen after NUL-containing input to verify no invalid character NULL warning fix: 过滤输入法事件中的 NUL 字节 1. 根因:inputMethodEvent 接收输入法的 commitString/preeditString 时未过滤 NUL 字节(\x00),NUL 字节经 insertSelectTextEx 写入文档 并在保存时持久化到文件 2. 方案:在传入 insertSelectTextEx 之前移除 NUL 字节,移除后若文本 为空则跳过插入 3. 影响:仅影响含 NUL 字节的文本(如搜狗软键盘输入),正常文本输入 不受影响 Influence: 1. 测试输入法正常输入文字(中文、英文、数字),验证无回归 2. 测试输入法提交含 NUL 字节的文本,验证 NUL 字节被过滤 3. 测试含 NUL 输入后保存并重新打开文件,验证不再提示无效字符NULL PMS: BUG-372753 --- src/editor/dtextedit.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/editor/dtextedit.cpp b/src/editor/dtextedit.cpp index 00bc6d77..0d5062ce 100644 --- a/src/editor/dtextedit.cpp +++ b/src/editor/dtextedit.cpp @@ -7593,7 +7593,9 @@ void TextEdit::inputMethodEvent(QInputMethodEvent *e) } bool isPreedit = !e->preeditString().isEmpty(); if (isPreedit || !e->commitString().isEmpty()) { - const QString &text = isPreedit ? e->preeditString() : e->commitString(); + QString text = isPreedit ? e->preeditString() : e->commitString(); + text.remove(QLatin1Char('\x00')); + if (!text.isEmpty()) { //列编辑添加撤销重做 if (m_bIsAltMod && !m_altModSelections.isEmpty()) { @@ -7610,6 +7612,7 @@ void TextEdit::inputMethodEvent(QInputMethodEvent *e) insertSelectTextEx(textCursor(), text); } } + } m_isSelectAll = false; }