From 1d9dbfda76b3a741505c8313bb5621168b847872 Mon Sep 17 00:00:00 2001 From: QiuSW <105186638@qq.com> Date: Thu, 20 Aug 2026 09:57:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(#48):=20keep=20PowerShell=20scripts=20ASCII?= =?UTF-8?q?=20=E2=80=94=20Chinese=20comments=20broke=20parsing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- scripts/start-server.ps1 | 18 ++++++++++++------ scripts/start-web.ps1 | 13 +++++++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/scripts/start-server.ps1 b/scripts/start-server.ps1 index af9249c..3014089 100644 --- a/scripts/start-server.ps1 +++ b/scripts/start-server.ps1 @@ -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" diff --git a/scripts/start-web.ps1 b/scripts/start-web.ps1 index 093c1f2..d652a2a 100644 --- a/scripts/start-web.ps1 +++ b/scripts/start-web.ps1 @@ -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