fix(#48): keep PowerShell scripts ASCII — Chinese comments broke parsing

PowerShell 5.1 reads a .ps1 with no BOM using the ANSI code page. Every
byte of a UTF-8 Chinese character is >= 0x80, so GBK pairs them up two at
a time; a comment line carrying an odd number of those bytes pairs its
last byte with the trailing newline and swallows it, folding the next
line into the comment. That commented out the `try {` I had added and
left `} catch { }` orphaned, which is the parse error reported at
startup — and it shifted the line numbers, which is why the earlier
PowerShell error positions never matched the file.

My previous Chinese comment survived only because its byte count happened
to be even. Both scripts are back to ASCII, matching the English already
used throughout them, with a note saying why it matters.

Also restores CRLF: .gitattributes marks *.ps1 eol=crlf, and rewriting
these files from Python had left them LF in the working tree.

Verified this time rather than handed over untested: Windows PowerShell
is reachable from WSL, so both scripts were parse-checked and run with
-ValidateConfigOnly, and the chcp block was executed on its own
(code page 65001, console encoding utf-8).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
QiuSW
2026-08-20 09:57:57 +08:00
co-authored by Claude Opus 5
parent bbc5fdba05
commit 1d9dbfda76
2 changed files with 21 additions and 10 deletions
+12 -6
View File
@@ -11,11 +11,16 @@ param(
$ErrorActionPreference = "Stop"
# Go 进程输出 UTF-8。不显式设定的话,中文日志会按控制台的 ANSI 代码页(简中为
# GBK)解码,显示成乱码——见 #48 启动日志。
# The Go processes emit UTF-8. Without this the console decodes their output
# using the ANSI code page (936 on Simplified Chinese systems) and every
# non-ASCII log line arrives as mojibake.
#
# 只设 [Console]::OutputEncoding 不够:PowerShell 5.1 解码子进程输出时还要看
# 控制台代码页,所以两个都得改。chcp 的输出丢弃掉,避免多打一行。
# Setting [Console]::OutputEncoding alone is not enough: PowerShell 5.1 decodes
# child process output by the console code page, so chcp has to change too.
#
# NOTE: keep this file pure ASCII. PowerShell 5.1 reads a .ps1 without a BOM as
# ANSI, and a comment line holding an odd number of UTF-8 high bytes pairs its
# last byte with the newline, swallowing it and commenting out the line below.
try {
$null = & chcp.com 65001
[Console]::OutputEncoding = [Text.Encoding]::UTF8
@@ -207,8 +212,9 @@ try {
Remove-Item Env:MYSQL_PWD -ErrorAction SilentlyContinue
}
# 让服务端自己读同一个 config.yaml,取出 syb 凭据等本地配置。
# 下面的 GOAUTO_* 变量优先级高于文件,所以数据库和端口仍以脚本算出的为准。
# Let the server read the same config.yaml for local values such as the SYB
# credentials. The GOAUTO_* variables below outrank the file, so the
# database and port stay exactly what this script computed.
$env:GOAUTO_CONFIG = $ConfigPath
$env:GOAUTO_DB_DRIVER = "mysql"
$env:GOAUTO_DB_DSN = "${DatabaseUser}:${plainPassword}@tcp(${DatabaseHost}:${DatabasePort})/${DatabaseName}?charset=utf8mb4&parseTime=True&loc=Local&timeout=5s"
+9 -4
View File
@@ -6,11 +6,16 @@ param(
$ErrorActionPreference = "Stop"
# Go 进程输出 UTF-8。不显式设定的话,中文日志会按控制台的 ANSI 代码页(简中为
# GBK)解码,显示成乱码——见 #48 启动日志。
# The Go processes emit UTF-8. Without this the console decodes their output
# using the ANSI code page (936 on Simplified Chinese systems) and every
# non-ASCII log line arrives as mojibake.
#
# 只设 [Console]::OutputEncoding 不够:PowerShell 5.1 解码子进程输出时还要看
# 控制台代码页,所以两个都得改。chcp 的输出丢弃掉,避免多打一行。
# Setting [Console]::OutputEncoding alone is not enough: PowerShell 5.1 decodes
# child process output by the console code page, so chcp has to change too.
#
# NOTE: keep this file pure ASCII. PowerShell 5.1 reads a .ps1 without a BOM as
# ANSI, and a comment line holding an odd number of UTF-8 high bytes pairs its
# last byte with the newline, swallowing it and commenting out the line below.
try {
$null = & chcp.com 65001
[Console]::OutputEncoding = [Text.Encoding]::UTF8