fix: preserve Locale scripts and extensions during parsing - #7816
Open
DarrenChangJR wants to merge 1 commit into
Open
fix: preserve Locale scripts and extensions during parsing#7816DarrenChangJR wants to merge 1 commit into
DarrenChangJR wants to merge 1 commit into
Conversation
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.
What this PR does and why
The Locale writer uses
Locale.toString(). For locales containing scripts orBCP-47 extensions, that representation includes an
_#suffix, for examplezh_HK_#Hantoren_US_#u-ca-japanese.The current reader treats the third underscore-delimited component as a
variant. As a result, scripts and Unicode locale extensions are silently lost.
It also maps the empty string emitted for
Locale.ROOTto null.This change preserves the existing JSON wire representation and extends only
the reader. Extended values are converted into a correctly ordered BCP-47 tag;
the existing language/country/variant path remains unchanged.
Tests
The expanded
LocaleTestcovers:zh-Hant-HKthrough text JSON while preserving the existing wire string;Locale.ROOTversus JSON null;Locale.CHINAtext and JSONB controls.Validation performed:
LocaleTest(six tests);mvn -pl core validate;coresuite: 7,978 tests, no failures or errors;parsing; the branch is equal without changing its wire string.
Checklist
中文说明
修改内容和原因
Locale writer 使用
Locale.toString()。当 locale 包含 script 或 BCP-47extension 时,该字符串会带有
_#后缀,例如zh_HK_#Hant和en_US_#u-ca-japanese。当前 reader 只按下划线解析 language、country 和 variant,因此会把 script
误当作 variant,并丢失 Unicode locale extension;同时还会把
Locale.ROOT对应的空字符串解析为 null。本修改保持现有 JSON 字符串格式不变,只扩展 reader:将
_#扩展格式重组为顺序正确的 BCP-47 tag;简单 language/country/variant 路径保持原逻辑。
测试
测试覆盖文本 JSON 中的
zh-Hant-HK、Unicode calendar extension、JSONB中的 script + extension 组合、
Locale.ROOT,以及原有Locale.CHINA用例。聚焦测试、Maven
validate和完整 7,978 个 core 测试均通过。