fix: hoist sanitize mapping to module constant, fix U+001E em-dash mismap#929
Merged
Conversation
…smap - Hoisted replacements dict to _CU_REPLACEMENTS module-level constant to avoid per-call allocation overhead. - Added _CU_BAD_CHARS set for O(1) early-exit when text has no corrupted chars. - Fixed U+001E mapping: was incorrectly mapped to U+2014 (em dash), now correctly maps to U+201E (double low-9 quotation mark) per the high-byte stripping model. - Added U+0014 -> U+2014 mapping for actual em dash corruption. - Reworded docstring to clarify no-op semantics. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
4 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the sanitize_cu_output utility used by the infra indexing scripts to correct corrupted Unicode characters emitted by the Content Understanding analyzeBinary API, while reducing per-call overhead and fixing an incorrect character mapping.
Changes:
- Hoisted the corrupted-control-character replacement mapping to a module-level constant and added a fast no-op early exit via
set.isdisjoint(). - Fixed the
U+001Emapping (now toU+201E) and added the correctU+0014→U+2014mapping for em dashes. - Updated the docstring to remove the misleading “zero-cost” wording and clarify no-op semantics.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Avijit-Microsoft
approved these changes
May 22, 2026
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.
Purpose
Addresses review feedback on PR #922 for the
sanitize_cu_outputfunction incontent_understanding_client.py:replacementsdict to module-level constant (_CU_REPLACEMENTS) to avoid per-call allocation. Added_CU_BAD_CHARSset withisdisjoint()early-exit for true no-op when text has no corrupted chars.U+001Ewas incorrectly mapped toU+2014(em dash). Per the high-byte stripping corruption model,U+001Ecorresponds toU+201E(double low-9 quotation mark). Added correctU+0014->U+2014mapping for actual em dash corruption.Does this introduce a breaking change?
Golden Path Validation
Deployment Validation
What to Check
Verify that the following are valid
sanitize_cu_outputcorrectly maps all corrupted control chars back to intended Unicode equivalents03_cu_process_data_text.pyand04_cu_process_custom_data.pyOther Information
Fixes review comments from PR #922 (comments by Copilot code review).