refactor(core): extract shared sanitizeUnicodeText from session-name/… - #2190
Merged
Astro-Han merged 1 commit intoAug 5, 2026
Merged
Conversation
…foreign-session (apache#1404) foreign-session.ts:sanitizeForeignText duplicated the session-name.ts unicode pipeline and the two had drifted: session-name was missing 8 code points foreign-session (and its own FOREIGN_UNSAFE_CHARS id guard) already covered — U+061C/200E/200F (bidi marks) and U+2060-2064 (invisible format chars). The control-char classes were written differently but are byte-equivalent (not real drift). Extract the pipeline into a shared pure helper sanitizeUnicodeText in a new text-sanitize.ts leaf module: - char classes = union (the stricter foreign coverage) - truncatedSuffix parameter: foreign appends '…' (default), session-name passes '' to preserve its silent-cap behavior (its test asserts the capped length is exactly 80) - helper boundary = clean+truncate only; type guard, empty-string policy, and Result-vs-string return stay with each caller, so signatures are unchanged and no downstream caller needs edits session-name gets a pure coverage gain (the 8 chars never appear in legitimate CJK/emoji text). Add one session-name test case locking in the newly-covered bidi marks and invisible operators so they can't silently drift back out of sync. Existing tests stay green. FOREIGN_UNSAFE_CHARS / isSafeForeignId (verbatim id guard) are out of scope and untouched.
16 tasks
Contributor
|
Thanks for this — I verified the extraction at character level against the pre-PR pipelines: the foreign call site is byte-identical (same regex sets, same ordering, same Three optional notes:
Nothing blocking — happy to approve. |
Astro-Han
approved these changes
Aug 5, 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.
Summary
foreign-session.ts:sanitizeForeignText duplicated the session-name.ts unicode pipeline and the two had drifted — session-name was missing 8 code points that foreign-session (and its own FOREIGN_UNSAFE_CHARS id guard) already covered: U+061C, U+200E, U+200F (bidi marks) and U+2060–U+2064 (invisible format chars).
I extracted the pipeline into a shared pure helper sanitizeUnicodeText(text, {maxCodePoints, truncatedSuffix}) in a new packages/core/src/text-sanitize.ts leaf module, which now holds the three character-class regexes as the single source of truth. The character classes take the union — the stricter foreign-session coverage — so session-name picks up the 8 previously-missing code points as a pure coverage gain (they never appear in legitimate CJK/emoji text, so no false positives).
Because the two callers disagree on truncation behavior and both are pinned by existing tests, I parameterized the suffix: foreign-session appends … (the default), while session-name passes '' to preserve its silent-cap behavior. The helper boundary is clean-and-truncate only; the type guard, empty-string policy, and Result-vs-string return shape stay with each caller, so both export signatures are unchanged and no downstream caller needs edits.
foreign-session.ts:sanitizeForeignText is now a thin wrapper around the helper, and session-name.ts:normalizeUserSessionName calls it with truncatedSuffix: '' (net −59 lines). I also exported sanitizeUnicodeText from index.ts and added one session-name test case locking in the newly-covered bidi marks and invisible operators so they can't silently drift back out of sync. FOREIGN_UNSAFE_CHARS and isSafeForeignId (the verbatim-rendered id guard) are a separate concern and left untouched.
Refs: #1404
Verification