已关闭
[Bug]: std.time 和 std.unicode 部分边界行为不符合预期 #603
Cangjie-ChenQian创建于  4月25日关闭于  4月27日
Cangjie-ChenQian仓颉Committer
4月25日 创建

发生了什么问题? | Describe the issue that occurred.

std.timestd.unicode 存在以下边界行为问题:

  • std.time 的时区 ID 校验过宽,Asia\Shanghai 这类包含反斜杠的非法 ID 未在参数校验阶段被拒绝,而是继续进入时区数据查找流程。
  • std.time 解析 TZif 数据时未校验 transition 时间严格递增,构造乱序 transition 的数据可以被接受,后续转换结果可能不可靠。
  • std.unicodeRune 级大小写 API 对特殊 Unicode 映射返回原字符,与 String 级 API 行为不一致,例如 ßʼn 等字符。
  • std.unicodeU+0130 在土耳其语、阿塞拜疆语小写转换场景下未按 locale 规则映射为 i

期望行为是什么? | What is the expected behavior?

  • 非法时区 ID 应在参数校验阶段抛出 IllegalArgumentException,避免继续进入文件查找或数据加载路径。
  • TZif transition 时间必须严格递增;乱序 transition 数据应被判定为无效并抛出 InvalidDataException
  • Rune 级大小写转换应与 String 级 API 的特殊 Unicode 映射保持一致。
  • U+0130 在土耳其语、阿塞拜疆语小写转换时应返回 i

如何复现该缺陷? | How to reproduce the bug?

可通过以下场景复现:

  • 调用 TimeZone.load("Asia\\Shanghai"),当前行为未在参数校验阶段拒绝该非法 ID。
  • 构造包含非递增 transition 时间的 TZif 数据并调用 TimeZone.loadFromTZData(...),当前行为未拒绝该数据。
  • 调用 Rune(0x00DF).toUpperCase()Rune(0x0149).toUpperCase(),当前行为与对应 String.toUpper() 结果不一致。
  • 调用 Rune(0x0130).toLowerCase(TR)Rune(0x0130).toLowerCase(AZ),当前行为未返回 locale 期望的小写 i

其他补充信息 | Additional information

本地已补充回归用例覆盖上述场景:

  • testsuites/LLT/API/std/time/datetime/test_parse_format_check_input.cj
  • testsuites/LLT/API/std/time/timezone/test_time_report_repros.cj
  • testsuites/LLT/API/std/unicode/test_unicode_report_repros.cj

本地验证结果:

  • 标准库构建通过。
  • std/time/datetime/test_parse_format_check_input.cj 通过,18 个用例通过。
  • std/time/timezone/test_time_report_repros.cj 通过,2 个目标回归用例通过。
  • std/unicode/test_unicode_report_repros.cj 通过,3 个用例通过。

cjc版本信息 | cjc version information

Cangjie Compiler: 1.1.0-alpha.20260414010024 (cjnative)
Target: x86_64-unknown-linux-gnu

分支版本信息 | Branch version information

likedislike
CCangjie-ChenQian仓颉Committer
4月25日 添加了label:bug
CCangjie-ChenQian仓颉Committer
4月25日 关联了pull request:fix: validate timezone data and unicode special casing
CCangjie-ChenQian仓颉Committer
4月25日 关联了pull request:test: add std time and unicode regression cases
CCangjie-ChenQian仓颉Committer
4月25日 添加了label:1.2.0-alpha.11
CCangjie-ChenQian仓颉Committer
4月27日 关联了pull request:fix(std.time): reject invalid zones and malformed transitions
CCangjie-ChenQian仓颉Committer
4月27日 关联了pull request:fix(std.time): reject invalid zones and malformed transitions
CCangjie-ChenQian仓颉Committer
4月27日 关联了pull request:test(std.time): add timezone regression cases
CCangjie-ChenQian仓颉Committer
4月27日 关联了pull request:test(std.time): add timezone regression cases
CCangjie-ChenQian仓颉Committer
4月27日 添加了label:1.1.31.2.0-alpha.16
CCangjie-ChenQian仓颉Committer
4月27日 修改了issue 的描述
CCangjie-ChenQian仓颉Committer
4月27日 修改了issue 的描述
CCangjie-ChenQian仓颉Committer
4月27日 关闭了 issue