Skip to content

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

fix(dsh): 带 UTF-8 BOM 的 DeepSeek Harness 配置文件不再读取失败 (#10295)

thisTomc22aea215323
diff --git a/src-tauri/src/dsh_config.rs b/src-tauri/src/dsh_config.rs
index ad5aa33f0..d8682aa9b 100644
--- a/src-tauri/src/dsh_config.rs
+++ b/src-tauri/src/dsh_config.rs
@@ -131,7 +131,11 @@ pub(crate) fn credentials_path() -> PathBuf {
fn read_text(path: &Path) -> Result<String, AppError> {
match fs::read_to_string(path) {
- Ok(text) => Ok(text),
+ // Windows editors may save a UTF-8 BOM, which DSH skips; entry offsets must not count it.
+ Ok(text) => Ok(text
+ .strip_prefix('\u{feff}')
+ .map(str::to_owned)
+ .unwrap_or(text)),
Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(String::new()),
Err(error) => Err(AppError::io(path, error)),
}
@@ -2027,6 +2031,46 @@ mod tests {
assert_eq!(fs::read(&credentials).unwrap(), previous_credentials);
}
+ #[test]
+ fn provider_read_and_write_accept_files_saved_with_utf8_bom() {
+ let temp = tempfile::tempdir().unwrap();
+ let path = temp.path().join("cordis.patch.yml");
+ let credentials = temp.path().join(".credentials.yaml");
+ let other = "- id: other\n config: {value: keep}\n";
+ fs::write(
+ &path,
+ format!("\u{feff}- id: llm-pi-ai\n config:\n providers: {{}}\n{other}"),
+ )
+ .unwrap();
+ fs::write(
+ &credentials,
+ "\u{feff}version: 1\nrefs: {OTHER_KEY: other}\nrecords: {}\n",
+ )
+ .unwrap();
+ assert!(get_providers_from(&path, &credentials).unwrap().is_empty());
+
+ save_paths_and_commit(
+ std::slice::from_ref(&path),
+ &credentials,
+ "gateway",
+ Some(editor_config()),
+ true,
+ || Ok(()),
+ )
+ .unwrap();
+ let text = read_text(&path).unwrap();
+ assert!(text.ends_with(other), "{text}");
+ assert_eq!(entries(&text).unwrap().len(), 2);
+ assert_eq!(
+ get_providers_from(&path, &credentials).unwrap()["gateway"]["options"]["apiKey"],
+ "test-value"
+ );
+ assert_eq!(
+ credential_document(&credentials).unwrap()["refs"]["OTHER_KEY"],
+ "other"
+ );
+ }
+
#[test]
fn provider_and_credentials_roll_back_together_on_failure() {
let temp = tempfile::tempdir().unwrap();