fix(lyrics): prevent Bengali romanizer crash on mixed-script text - #426
Merged
Merged
Conversation
BengaliRomanizer.romanize(_:) trapped with "String index is out of bounds"
when a line mixed Bengali with another non-Latin script the bn-locale
tokenizer cannot transcribe (e.g. Bengali + Thai). The fallback branch
indexed the Swift String by grapheme cluster (text.index(_:offsetBy:)),
but CFStringTokenizer token ranges are measured in UTF-16 code units.
Bengali matras (combining marks) make the grapheme count smaller than the
UTF-16 count, so the UTF-16 location overshoots endIndex and the process
traps.
Index via NSString (UTF-16 code units) so the unit matches the CFRange,
mirroring the ThaiRomanizer / JapaneseRomanizer siblings. No
transliteration-table or sibling-romanizer changes.
Add BengaliRomanizerTests: a cross-script crash regression
("বাংলা ก" traps at HEAD, returns "bānlāก" after the fix), a pure-Bengali
control, and an emoji passthrough guard. Assertions are kept as weak as
the sibling romanizer tests so they do not depend on per-OS tokenizer
transcription data across the macOS 15 + 26 CI matrix.
Co-Authored-By: Claude <noreply@anthropic.com>
Contributor
Author
|
Heads-up on the red It fails only on |
sozercan
approved these changes
Aug 10, 2026
Yoddikko
pushed a commit
to Yoddikko/kasetPlus
that referenced
this pull request
Aug 27, 2026
…zercan#426) Co-authored-by: Claude <noreply@anthropic.com>
Yoddikko
added a commit
to Yoddikko/kasetPlus
that referenced
this pull request
Aug 27, 2026
…zercan#448 Cherry-picked from sozercan/kaset: - sozercan#426 Bengali romanizer mixed-script crash fix - sozercan#425 refresh Home suggestions on demand (adapted: kept fork shorts aggregation + chip-bar callers pass forceRefresh:false) - sozercan#447 stop page URL stored as track artwork - sozercan#448 eliminate cross-suite unit test flakes (WebKit cookie handling) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012LaRrBbQsc5W5agXFkYc7u
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.
Description
BengaliRomanizer.romanize(_:)could trap withFatal error: String index is out of boundswhen a line mixed Bengali with another non-Latin script the Bengali-locale tokenizer cannot transcribe (e.g. a Bengali lyric line containing a Thai/CJK/Hangul/Arabic word). The fallback branch indexed the SwiftStringby grapheme cluster (text.index(_:offsetBy:)), butCFStringTokenizertoken ranges are measured in UTF-16 code units. Bengali matras (combining marks) make the grapheme count smaller than the UTF-16 count, so the UTF-16locationovershootsendIndexand the process traps. This harmonizes the romanizer with itsThaiRomanizer/JapaneseRomanizersiblings, which already index viaNSString.AI Prompt (Optional)
🤖 AI Prompt Used
AI Tool: Claude Code
Type of Change
Related Issues
Changes Made
BengaliRomanizer.swift: capturelet nsText = text as NSStringand extract the fallback (non-transliterable) token viansText.substring(with: NSRange(location:length:))instead of grapheme-clusterStringindexing, matchingThaiRomanizer/JapaneseRomanizer.RomanizationTests.swift: addBengaliRomanizerTests— a cross-script crash regression (বাংলা ก, RED→GREEN), a pure-Bengali control, and an emoji passthrough guard.Testing
swift test --skip KasetUITests)RED (HEAD):
romanize("বাংলা ก")traps —Swift/StringCharacterView.swift:158: Fatal error: String index is out of bounds(signal 5). GREEN (fix): returnsbānlāก; full suite green.Checklist
swiftlint --strict && swiftformat .Screenshots
n/a — no UI change.
Additional Notes
CFStringTokenizerwith aLatinTranscriptionequal to itself, so it takes the transcription branch (not the buggy fallback) and already worked. The crash requires a token that is emitted without a Latin transcription — i.e. another non-Latin script thebnlocale can't transcribe (Thaiก, CJK, Hangul, Arabic). Verified empirically by instrumenting the tokenizer.LatinTranscriptionavailability can vary across macOS versions and CI spans macOS 15 + 26, so asserting the raw glyph would be OS-fragile.♪/♫/★(they aren't emitted as tokens). That is a tokenizer-emission characteristic, not the indexing bug fixed here, and is left unchanged.