Skip to content

ci(encoding): reject invalid UTF-8 and mojibake regressions#426

Open
WHUTcjh-2024 wants to merge 1 commit into
TencentCloud:mainfrom
WHUTcjh-2024:codex/issue-387-encoding-guard
Open

ci(encoding): reject invalid UTF-8 and mojibake regressions#426
WHUTcjh-2024 wants to merge 1 commit into
TencentCloud:mainfrom
WHUTcjh-2024:codex/issue-387-encoding-guard

Conversation

@WHUTcjh-2024

Copy link
Copy Markdown

ci(encoding): reject invalid UTF-8 and mojibake regressions

Description | 描述

为受版本控制的文本文件增加可测试的编码守卫,防止 PowerShell/旧代码页链路产生的静默乱码进入仓库。

  • 使用 fatal UTF-8 decoder 拒绝非 UTF-8 字节;
  • 检测 U+FFFD 替换字符;
  • 要求 PowerShell .ps1 使用 UTF-8 BOM,覆盖 issue 中的 L1 防线;
  • 精确识别 Windows-1252 和中文旧代码页的常见乱码特征;
  • 仅扫描 git ls-files 返回的已跟踪文本文件,不误扫二进制资产和本地产物;
  • GitHub Actions 输出文件、行、列注解,可直接定位问题。

检测器允许正常中文、日文、重音拉丁字符和 emoji,避免“禁止所有非 ASCII”造成的误报。

Related Issue | 关联 Issue

Closes #387

Change Type | 修改类型

  • Bug fix | Bug 修复
  • New feature | 新功能
  • Documentation update | 文档更新
  • Code optimization | 代码优化

Self-test Checklist | 自测清单

  • Verified locally | 本地验证通过
  • No existing features affected | 无影响现有功能

Additional Notes | 其他说明

本地验证:

node --test scripts/check-text-encoding.test.mjs
# 8 passed

node scripts/check-text-encoding.mjs
# Encoding check passed (162 tracked text files).

vitest run
# 4 files, 67 tests passed (Node 24.14.0)

npm run build
# passed (Node 24.14.0)

该 PR 仅增加编码检测与 CI 接入,不包含适配器、SDK 或其他功能改动。

@Maxwell-Code07

Copy link
Copy Markdown
Collaborator

Thank you for your attention! We will conduct a review and respond to you as soon as possible.

@YOMXXX

YOMXXX commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review note after local verification:

The encoding guard itself looks useful and the local verification passed:

  • node --test scripts/check-text-encoding.test.mjs (8/8 passed)
  • node scripts/check-text-encoding.mjs (162 tracked text files passed)
  • COREPACK_ENABLE_AUTO_PIN=0 pnpm test (67/67 passed)
  • COREPACK_ENABLE_AUTO_PIN=0 pnpm build
  • git diff --check

I would not approve this branch as-is because the PR diff includes unrelated churn outside the encoding guard:

  • package.json changes the package version, changes the files entry from src/ to src, and adds zod; these are unrelated to encoding detection.
  • .github/workflows/pr-ci.yml appears to have broad line-ending / formatting churn, making the functional CI change harder to review.

Recommended cleanup: keep only the encoding scripts, the two package scripts (check:encoding, test:encoding), and the minimal CI job/step wiring. Removing unrelated package/line-ending churn should make this approve-ready.

@WHUTcjh-2024

Copy link
Copy Markdown
Author

OK, i will see it

@WHUTcjh-2024 WHUTcjh-2024 force-pushed the codex/issue-387-encoding-guard branch from 8f25cb2 to b922472 Compare July 9, 2026 09:54
@WHUTcjh-2024

Copy link
Copy Markdown
Author

Thanks for the review and verification.

I cleaned this up as requested and force-updated the branch to a single clean commit. The PR diff now keeps only:

  • the two encoding scripts
  • the two package scripts: check:encoding and test:encoding
  • the minimal Encoding Guard CI job wiring

I removed the unrelated package/workflow churn from the final PR diff; there are no package version, files, dependency, or broad line-ending changes left.

Verified locally:

  • node --test scripts/check-text-encoding.test.mjs (8/8 passed)
  • node scripts/check-text-encoding.mjs (162 tracked text files passed)
  • npm run test:encoding
  • npm run check:encoding
  • local build steps via tsdown and the three script tsc builds
  • git diff --check

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.

[Question] Encoding defense: PowerShell -> Git mojibake prevention (5-layer)

3 participants