Conversation
andrew-polk
left a comment
There was a problem hiding this comment.
@andrew-polk reviewed 6 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nabalone).
components/language-chooser/common/find-language/searchForLanguage.ts line 105 at r1 (raw file):
// handled // by the searchResultModifier const correctedCode = code === "zh" ? "cmn" : code;
devin:
components/language-chooser/common/find-language/searchForLanguage.ts:R105
Case-sensitive zh check breaks case-insensitive contract of getLanguageBySubtag
The new code === "zh" check at searchForLanguage.ts:105 is case-sensitive, but getLanguageBySubtag (and by extension parseLangtagFromLangChooser) is expected to be case-insensitive, as demonstrated by the existing test parseLangtagFromLangChooser("cE-CyRl-rU") succeeding.
Root Cause and Impact
When parseLangtagFromLangChooser("ZH-Hant") is called, splitTag does not normalize case (components/language-chooser/common/find-language/languageTagUtils.ts:241), so languageSubtag is "ZH". Then getLanguageBySubtag("ZH", searchResultModifier) is called. Because "ZH" !== "zh", the correction to "cmn" is skipped, and correctedCode remains "ZH".
Fuse.js (which is case-insensitive by default) then searches for "ZH" and may find the zho macrolanguage entry (which has languageSubtag: "zh") instead of the intended cmn entry.
- Without a modifier: Returns the
zhomacrolanguage entry instead of the data-richcmnentry. - With
defaultSearchResultModifier:zhois inEXCLUDED_PROBLEMATIC_LANGUAGE_CODES(searchResultModifiers.ts:246), so it gets filtered out, and the function returnsundefined— causingparseLangtagFromLangChooserto fail for a valid Chinese tag.
Impact: Any caller passing an uppercase or mixed-case "zh" language subtag (e.g. "ZH-Hant", "Zh-CN") to parseLangtagFromLangChooser or getLanguageBySubtag will get incorrect results or undefined for Chinese.
2c24f9d to
fe666d5
Compare
andrew-polk
left a comment
There was a problem hiding this comment.
@andrew-polk reviewed 2 files and all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @nabalone).
andrew-polk
left a comment
There was a problem hiding this comment.
@andrew-polk resolved 1 discussion.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @nabalone).
This change is