FIX: preserve content and word boundaries in NatoConverter - #2399
Merged
Roman Lutz (romanlutz) merged 3 commits intoAug 14, 2026
Merged
Conversation
Non-alphabetic characters (digits, punctuation) are now passed through unchanged instead of being silently erased, so an encoded prompt keeps its full content and non-empty input never converts to an empty string. Matches the passthrough behavior of Arabizi/Atbash and the fidelity fix for BrailleConverter (microsoft#2309). Regression tests updated for digits, punctuation, and no-letters input. Signed-off-by: fei <204683769+feiiiiii5@users.noreply.github.com>
Refactor NatoConverter onto WordLevelConverter, represent source spaces explicitly, and preserve unmapped Unicode without case expansion. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: c9450170-29e5-4918-b1bc-71f6d9f46402
Roman Lutz (romanlutz)
approved these changes
Aug 14, 2026
Roman Lutz (romanlutz)
enabled auto-merge
August 14, 2026 22:42
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.
Root Cause
NatoConverteruppercased the entire prompt and retained only characters present in its A-Z map. This silently deleted digits, punctuation, Unicode, and spaces. As a result:"123!@#"became an empty prompt."HI THERE"and"HITHERE"produced identical output because word boundaries disappeared.text.upper()would also mutate or expand unmapped Unicode such asé,ß, andı.That changes prompt semantics and is inconsistent with the prompt-fidelity behavior of sibling converters.
Fix
Refactor
NatoConverterto inherit from the existingWordLevelConverterabstraction:convert_word_async.<space>token so word boundaries remain distinguishable from the spaces between NATO code words.Examples:
"Hello, world!"→"Hotel Echo Lima Lima Oscar , <space> Whiskey Oscar Romeo Lima Delta !""123!@#"→"1 2 3 ! @ #""HI THERE"→"Hotel India <space> Tango Hotel Echo Romeo Echo", distinct from"HITHERE"é,ß,ı, andñremains unchanged.Tests
Coverage includes letters and casing, digits, punctuation, empty and space-only prompts, Unicode passthrough, explicit word boundaries, word-selection strategies, and unsupported input types.
Targeted converter suites pass: 32 tests. Ruff formatting/linting and repository commit hooks also pass.
Diff Scope
Two files:
pyrit/converter/nato_converter.pyandtests/unit/converter/test_nato_converter.py.AI Disclosure
The bug analysis and implementation were AI-assisted, then reviewed and validated against the converter contracts and targeted test suites.
Closes #2398