Repository navigation
FIX: mask words written with combining marks instead of skipping them - #3155
Merged
Roman Lutz (romanlutz) merged 4 commits intoOct 17, 2026
Merged
Roman Lutz (romanlutz) merged 4 commits into
Roman Lutz (romanlutz) merged 4 commits into
Conversation
The tokenizer joins letter runs separated by nothing but combining marks, so pointed Hebrew and Arabic, Devanagari and NFD text are scanned as whole words. Joiners still make a word a fragment, as before. Clues count letters rather than code points, and the word key is normalized so a composed and a decomposed spelling are one word.
Contributor
Author
|
@microsoft-github-policy-service agree |
Roman Lutz (romanlutz)
requested changes
Oct 13, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bff8f168-7232-4586-9d79-d59da7d0ca0b
Keep combining marks attached in all puzzle encodings and count the same canonical letter units in clues. Reject complete alphanumeric, underscore, and joined tokens before masking, and normalize folded Unicode keys so canonical case variants share a placeholder. Cover all three public puzzle paths in NFC and NFD. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bff8f168-7232-4586-9d79-d59da7d0ca0b
Roman Lutz (romanlutz)
approved these changes
Oct 17, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: bff8f168-7232-4586-9d79-d59da7d0ca0b
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.
Follow-up to #3051, which Aditya Malkar (@adimalkar) suggested at the end of that review: now that a skipped fragment is never masked, masking pointed scripts only needs the tokenizer to treat combining marks as part of the word.
That turned out to be most of it, but not all of it. Two other things had to change, and one of them I only found by sweeping rather than reading.
What changes
שָׁלוֹם עוֹלָם(niqqud)ValueError[WORD1] [WORD2]مَرْحَبًا بِالْعَالَم(harakat)ValueError[WORD1] [WORD2]सिस्टम हैक कैसे करेंValueError[WORD1] हैक [WORD2] [WORD3]café crème exploitcafé crème [WORD1]café [WORD1] [WORD2]café crème exploitcafé [WORD1] [WORD2]अक्षर,écoleami(joiners)ValueErrorh4ck3r,abc²The tokenizer.
\bfalls inside a word that uses combining marks, so the pattern returns fragments. Runs separated by nothing but marks are joined back into one word and trailing marks come with it. Selection, placeholder ordering and replacement all run off_iter_words, so nothing else had to move — that is what #3051 bought.Joiners are deliberately left alone.
_is_word_continuationstill rejects a word adjoining a ZWJ or ZWNJ, because a joiner is not part of the word it shapes. The five joiner tests added in review pass unchanged. Only the mark behaviour is what this PR changes.Clues counted code points.
f"{len(self.text)}-letter"would promise a seven-letter word forשָׁלוֹם, which is four letters written with seven code points. It counts non-continuations now. The same bug was latent for NFD Latin, where decomposedcaféis five code points.The word key was not stable across normalization forms. I found this by running 2000 random composed-vs-decomposed prompts rather than by reading: 136 disagreed on which word got masked.
_word_keywascasefold()alone, and"système"composed and decomposed fold to different strings, so they became two words and the alphabetical tie-break in_rank_candidatespicked whichever sorted first in that form. Normalizing first takes it to 2000/2000. It also meanscaféandcaféin one prompt are now one word with one placeholder.Tests
Three tests from #3051 (six cases) assert the old skip behaviour for marks, so they flip from "raises" to "masks" — I rewrote them rather than adding around them. The
école/école+acute test still passes, but for a different reason: the second one is now a word in its own right rather than a fragment, so its comment says that instead.tests/unit/converter: 2175 → 2181 passing, 64 skipped. ruff check and format clean. Both normalization tests fail with the tokenizer change alone and pass with the key fix, so they pin the right thing.Closes the follow-up from #3022.