Compare commits

...
Author SHA1 Message Date
l0ng-ai 5bf25391d5 fix(run): read .NET launch profiles from a launchSettings.json with a byte order mark
Visual Studio saves launchSettings.json with a UTF-8 byte order mark, which
serde_json rejects, so a project's launch profiles came out empty: none were
offered or detected, and a configuration naming one failed with "launch
profile is missing". jsonc::strip now drops a leading byte order mark, which
also covers the other JSONC files read through it (devcontainer.json,
.vscode/launch.json, tsconfig.json).
2026-11-15 00:47:28 +08:00
2 changed files with 11 additions and 1 deletions

No files matched your search

+9 -1
View File
@@ -1,8 +1,10 @@
//! JSON with comments (`devcontainer.json`, `deno.jsonc`, `tsconfig.json`): turned
//! into plain JSON for `serde_json`.
/// Strips `//` and `/* */` comments and trailing commas so JSONC parses as JSON.
/// Strips `//` and `/* */` comments, trailing commas and a leading byte order mark (Visual
/// Studio writes one into `launchSettings.json`) so JSONC parses as JSON.
pub fn strip(src: &str) -> String {
let src = src.strip_prefix('\u{feff}').unwrap_or(src);
let mut out = String::with_capacity(src.len());
let mut chars = src.chars().peekable();
let mut in_str = false;
@@ -87,4 +89,10 @@ mod tests {
assert_eq!(v["url"], "https://x.dev//y /* no */");
assert_eq!(v["q"], "say \"hi\",");
}
#[test]
fn drops_a_byte_order_mark() {
let v: serde_json::Value = serde_json::from_str(&strip("\u{feff}{ \"a\": 1 }")).unwrap();
assert_eq!(v["a"], 1);
}
}
+2
View File
@@ -68,6 +68,8 @@ fn profiles_filter_and_preserve_launch_properties() {
assert_eq!(p["http"].command_line_args, "--message \"hello world\"");
assert_eq!(p["http"].working_directory, "work");
assert!(parse_profiles("invalid").is_empty());
// Visual Studio saves launchSettings.json with a byte order mark.
assert_eq!(parse_profiles(&format!("\u{feff}{PROFILES}")).len(), 2);
}
#[test]