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"]); + } }