From ce7eb155b0f32f104863f02ca8120d7e729ce12b Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Tue, 10 Nov 2026 23:20:58 +0800 Subject: [PATCH] fix(http): read environment files saved with a byte order mark (#2547) Editors on Windows such as Notepad save UTF-8 with a BOM, which serde_json rejects, so such an http-client.env.json offered no environments. Refs #2435 --- crates/ide-http/src/env.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/crates/ide-http/src/env.rs b/crates/ide-http/src/env.rs index 84ae7cc54..2a693a58f 100644 --- a/crates/ide-http/src/env.rs +++ b/crates/ide-http/src/env.rs @@ -52,6 +52,8 @@ fn search_dirs(file: Option<&Path>, root: Option<&Path>) -> Vec { } fn parse_env(text: &str) -> IdeResult { + // Editors on Windows (Notepad) save UTF-8 with a byte order mark, which serde_json rejects. + let text = text.strip_prefix('\u{feff}').unwrap_or(text); let value: serde_json::Value = serde_json::from_str(text).map_err(|e| IdeError::invalid(format!("invalid environment file: {e}")))?; let mut out = EnvMap::new(); @@ -262,4 +264,12 @@ mod tests { let envs = Environments::load(Some(&other.path().join("s.http")), Some(root)).unwrap(); assert_eq!(envs.names(), vec!["dev"]); } + + #[test] + fn reads_env_files_saved_with_a_byte_order_mark() { + let tmp = tempfile::tempdir().unwrap(); + std::fs::write(tmp.path().join(PUBLIC_FILE), "\u{feff}{\"dev\":{\"host\":\"h\"}}").unwrap(); + let envs = Environments::load(Some(&tmp.path().join("a.http")), Some(tmp.path())).unwrap(); + assert_eq!(envs.names(), vec!["dev"]); + } }