Accept a UTF-8 BOM at the start of lightcraft-cli --script files

Fixes #2937

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-25 17:16:44 +00:00
co-authored by Claude Haiku 5.5
parent 03c88c166c
commit 286154a17c
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -557,6 +557,8 @@ fn run(args: &[String]) -> Result<(), String> {
} else {
std::fs::read_to_string(path).map_err(|e| format!("{path}: {e}"))?
};
// Windows PowerShell 5.1 writes a UTF-8 BOM; it is not part of the first JSON line.
let text = text.strip_prefix('\u{feff}').unwrap_or(&text);
for (n, line) in text.lines().enumerate().filter(|(_, l)| !l.trim().is_empty() && !l.trim_start().starts_with('#')) {
let v: Value = serde_json::from_str(line).map_err(|e| format!("{path}:{}: {e}", n + 1))?;
// `{"command": id, "params": …}` or a control request `{"method": m, "params": …}`
@@ -851,6 +853,8 @@ fn snapshot(args: &[String]) -> Result<(), String> {
let mut failed = 0usize;
if let Some(script) = &script {
let text = std::fs::read_to_string(script).map_err(|e| format!("{script}: {e}"))?;
// Windows PowerShell 5.1 writes a UTF-8 BOM; it is not part of the first JSON line.
let text = text.strip_prefix('\u{feff}').unwrap_or(&text);
let mut out = std::io::stdout().lock();
for (n, line) in text.lines().enumerate() {
let line = line.trim();