From 7399c68ec1a2c3dd325d0d41bdaf5017e2d3fb9f Mon Sep 17 00:00:00 2001 From: Mehul Wagde Date: Fri, 31 Jul 2026 00:12:42 +0530 Subject: [PATCH] fix: use strip-json-comments instead of fragile regex for JSONC parsing The hand-rolled removeJsonComments() regex strips // content even when it appears inside JSON string values (e.g. shell commands, file paths with // in them), causing valid settings.json files to be silently skipped. Replace with the strip-json-comments library which properly handles string context when stripping comments from JSONC content. Fixes firecrawl/firecrawl#3976 --- package.json | 1 + src/utils/web-defaults.ts | 9 ++------- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 66923b8f2b..7ebb4185ee 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "@inquirer/prompts": "^8.2.1", "commander": "^14.0.2", "firecrawl": "4.24.0", + "strip-json-comments": "^5.0.0", "yaml": "^2.9.0", "zod-to-json-schema": "3.24.6" } diff --git a/src/utils/web-defaults.ts b/src/utils/web-defaults.ts index 1419acf6ac..bcb3df449f 100644 --- a/src/utils/web-defaults.ts +++ b/src/utils/web-defaults.ts @@ -1,6 +1,7 @@ import { promises as fs } from 'fs'; import os from 'os'; import path from 'path'; +import stripJsonComments from 'strip-json-comments'; const CLAUDE_DENY_TOOLS = ['WebSearch', 'WebFetch'] as const; const CODEX_WEB_SEARCH_DISABLED = 'web_search = "disabled"'; @@ -37,12 +38,6 @@ async function writeText(filePath: string, content: string): Promise { await fs.writeFile(filePath, content, 'utf8'); } -function removeJsonComments(content: string): string { - return content - .replace(/\/\*[\s\S]*?\*\//g, '') - .replace(/(^|[^:\\])\/\/.*$/gm, '$1'); -} - async function configureClaudeDefaults( undo: boolean ): Promise { @@ -52,7 +47,7 @@ async function configureClaudeDefaults( if (existing && existing.trim()) { try { - config = JSON.parse(removeJsonComments(existing)); + config = JSON.parse(stripJsonComments(existing)); } catch { return { agent: 'Claude Code',