From 9ab090a2b2cf7f71b73959f411d21d0e16c9f492 Mon Sep 17 00:00:00 2001 From: xintaofei Date: Sun, 12 Apr 2026 12:00:47 +0800 Subject: [PATCH] fix(acp): avoid false-positive comment detection on URLs in opencode.json The naive // and /* check triggered on URLs like https://... inside string values. Now we only reject the file as JSONC when serde_json parsing fails AND comment-like sequences are found. --- src-tauri/src/acp/opencode_plugins.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src-tauri/src/acp/opencode_plugins.rs b/src-tauri/src/acp/opencode_plugins.rs index dc8a9ca..409d7a4 100644 --- a/src-tauri/src/acp/opencode_plugins.rs +++ b/src-tauri/src/acp/opencode_plugins.rs @@ -283,10 +283,14 @@ pub(crate) fn atomic_rewrite_opencode_json( let raw = fs::read_to_string(path) .map_err(|e| format!("Failed to read {}: {e}", path.display()))?; - if json_has_comments(&raw) { + // Try parsing first. If serde_json succeeds the file is valid JSON + // and any "//" or "/*" sequences live inside string values — not real + // comments. Only reject when parsing *fails* and the raw text looks + // like it might be JSONC (actual comments would cause a parse error). + if serde_json::from_str::(&raw).is_err() && json_has_comments(&raw) { return Err( - "opencode.json contains comments (// or /*). Refusing to rewrite to avoid data loss. \ - Please edit the file manually." + "opencode.json appears to be JSONC (contains comments). Refusing to rewrite to avoid \ + data loss. Please edit the file manually." .to_string(), ); }