Skip to content

fix: preserve Locale scripts and extensions during parsing - #7816

Open
DarrenChangJR wants to merge 1 commit into
alibaba:mainfrom
DarrenChangJR:fix/locale-script-extensions
Open

fix: preserve Locale scripts and extensions during parsing#7816
DarrenChangJR wants to merge 1 commit into
alibaba:mainfrom
DarrenChangJR:fix/locale-script-extensions

Conversation

@DarrenChangJR

Copy link
Copy Markdown

What this PR does and why

The Locale writer uses Locale.toString(). For locales containing scripts or
BCP-47 extensions, that representation includes an _# suffix, for example
zh_HK_#Hant or en_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.ROOT to 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 LocaleTest covers:

  • zh-Hant-HK through text JSON while preserving the existing wire string;
  • a Unicode calendar extension;
  • a combined script and extension through JSONB;
  • Locale.ROOT versus JSON null;
  • the existing Locale.CHINA text and JSONB controls.

Validation performed:

  • focused LocaleTest (six tests);
  • mvn -pl core validate;
  • clean full core suite: 7,978 tests, no failures or errors;
  • external facade matrix: the 2.0.64 script-bearing value is unequal after
    parsing; the branch is equal without changing its wire string.

Checklist

  • Existing simple Locale wire representations are unchanged.
  • Script and Unicode extension data are preserved.
  • Text JSON, JSONB, and root-locale paths are covered.
  • No public API change is required.
中文说明

修改内容和原因

Locale writer 使用 Locale.toString()。当 locale 包含 script 或 BCP-47
extension 时,该字符串会带有 _# 后缀,例如 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 测试均通过。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant