Skip to content

fix(script_translator): excluded words cause crashes#1152

Merged
ksqsf merged 1 commit intomasterfrom
fix/dictionary_exclude_crash
Mar 31, 2026
Merged

fix(script_translator): excluded words cause crashes#1152
ksqsf merged 1 commit intomasterfrom
fix/dictionary_exclude_crash

Conversation

@ksqsf
Copy link
Copy Markdown
Member

@ksqsf ksqsf commented Mar 28, 2026

fix #1149

之前對於每個 phrase length,phrase dict iter 一定會有至少一個結果。但在引入 dict_filter 後,對於某個 phrase length,有可能所有結果均被刪掉,導致其結果爲空。

本 PR 將 PrepareCandidate 邏輯修改爲循環,使之在某 iter 爲空時再繼續嘗試下一個 phrase length。

@ksqsf ksqsf requested review from Copilot and lotem March 28, 2026 11:16
@ksqsf ksqsf force-pushed the fix/dictionary_exclude_crash branch from 65454da to e7e59e0 Compare March 28, 2026 11:17
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

此 PR 旨在修复 dictionary_exclude(黑名单过滤)引入后,某些 code length 下候选被全部过滤导致的空结果,从而触发 Weasel 崩溃的问题(#1149)。

Changes:

  • 调整 ScriptTranslation::PrepareCandidate(),在遇到空 iterator/空 entry 时循环跳过,尝试找到下一个可用候选。
  • 修改 DictEntryIterator::Next() 的返回值逻辑,以反映过滤后是否还有可用 entry。

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/rime/gear/script_translator.cc PrepareCandidate() 增加循环与空 entry 跳过逻辑,避免因过滤导致候选为空时崩溃
src/rime/dict/dictionary.cc 调整 DictEntryIterator::Next() 的返回语义以适配过滤场景

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ksqsf ksqsf force-pushed the fix/dictionary_exclude_crash branch from e7e59e0 to e3f5284 Compare March 28, 2026 11:24
@ksqsf ksqsf self-assigned this Mar 28, 2026
})) {
UserDictEntryIterator& uter = user_phrase_iter_->second;
const auto& entry = uter.Peek();
if (!entry) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

老師,!entry 這可能是一個錯誤信號!

此時 uter.exhausted() 能否正確反映還會不會出詞?

(出詞的 iterator 類型,也包括 Translation)之前一直遵循這樣的原則:

  • 若不會再出詞,必有 iterator.exhausted() == true
  • 若會出詞,即 iterator.exhausted() == false,則 iterator.Peek() 須給出非空的值。

我認爲在這裏判斷,是在下游爲 iterator 的錯誤兜底。
可 iterator 本身仍然有錯誤的輸出,若其他代碼引用,極易引發類似故障。

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uter 目前没有 filter ,这段是顺带加上的。先删除之。

单个 iter 本身的 exhausted() 和 Peek() 是没问题的。问题只在于 script translator 的逻辑没有考虑到 dict filter 造成「某 phrase length 可能没有结果」,所以我判断应当在这里修改。现在把这个判断修改为 exhausted() ,或许更易理解。

@ksqsf ksqsf force-pushed the fix/dictionary_exclude_crash branch from e3f5284 to d0bf9f2 Compare March 29, 2026 14:55
@ksqsf
Copy link
Copy Markdown
Member Author

ksqsf commented Mar 31, 2026

ping @lotem

Copy link
Copy Markdown
Member

@lotem lotem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

謝謝!收錄吧!

@ksqsf ksqsf merged commit 4218af0 into master Mar 31, 2026
20 checks passed
@ksqsf ksqsf deleted the fix/dictionary_exclude_crash branch March 31, 2026 09:12
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.

输入dictionary_exclude中三个字及以上的词汇的拼音时导致Weasel崩溃

3 participants