Skip to content

Commit d8e5cff

Browse files
committed
fix: validate embedded config encoding in CI builds
1 parent 832be2d commit d8e5cff

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

.github/workflows/tauri-build-win-official.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ jobs:
140140
Set-ConfigValue '^(updater_temp_dir\s*=\s*)".*"$' "${{ env.APP_UPDATER_TEMP_DIR }}"
141141
Set-ConfigValue '^(downlaod_url\s*=\s*)".*"$' "${{ env.APP_WEBVIEW_DOWNLOAD_URL }}"
142142
143-
Set-Content -Path $configPath -Value $content -NoNewline
143+
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
144+
$resolvedConfigPath = (Resolve-Path $configPath).Path
145+
[System.IO.File]::WriteAllText($resolvedConfigPath, $content, $utf8NoBom)
144146
145147
# 在 CI 构建期间使用 fixed 版本的 Tauri 配置
146148
# 先将 src-tauri/tauri.conf.fixed.json 覆盖为 src-tauri/tauri.conf.json,

.github/workflows/tauri-release-win.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ jobs:
8686
Set-ConfigValue '^(updater_temp_dir\s*=\s*)".*"$' "${{ env.APP_UPDATER_TEMP_DIR }}"
8787
Set-ConfigValue '^(downlaod_url\s*=\s*)".*"$' "${{ env.APP_WEBVIEW_DOWNLOAD_URL }}"
8888
89-
Set-Content -Path $configPath -Value $content -NoNewline
89+
$utf8NoBom = New-Object System.Text.UTF8Encoding($false)
90+
$resolvedConfigPath = (Resolve-Path $configPath).Path
91+
[System.IO.File]::WriteAllText($resolvedConfigPath, $content, $utf8NoBom)
9092
9193
- name: Use fixed Tauri config
9294
shell: powershell

src-tauri/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,15 @@ mod config_encrypt {
385385
);
386386
});
387387

388+
std::str::from_utf8(&config_bytes).unwrap_or_else(|e| {
389+
panic!(
390+
"[BUILD ERROR] Config file '{}' is not valid UTF-8: {}\n\
391+
Please ensure workflow/local scripts write this file with UTF-8 encoding.",
392+
config_path.display(),
393+
e
394+
);
395+
});
396+
388397
let encrypted = crypto::encrypt(&config_bytes).expect("Failed to encrypt config");
389398

390399
let out_path = Path::new(&out_dir).join("config_encrypted.bin");

0 commit comments

Comments
 (0)