Skip to content

fix(web-defaults): safely parse JSON with strings containing slashes … - #247

Open
shobhitagnihotri69 wants to merge 1 commit into
firecrawl:mainfrom
shobhitagnihotri69:fix/219-preserve-strings-with-slashes-in-web-defaults
Open

shobhitagnihotri69 wants to merge 1 commit into
firecrawl:mainfrom
shobhitagnihotri69:fix/219-preserve-strings-with-slashes-in-web-defaults

Conversation

@shobhitagnihotri69

@shobhitagnihotri69 shobhitagnihotri69 commented Sep 17, 2026

Copy link
Copy Markdown

Summary

Fixes #219.

When firecrawl setup defaults reads existing configuration files (such as Claude desktop config or VS Code settings), regex-based comment stripping (\/\/.*$) was aggressively removing characters inside string literals (e.g. Read(//c/Users/...)). This produced malformed JSON syntax errors (SyntaxError: Expected double-quoted property name in JSON...) and silently skipped saving web default configurations.

Changes

  • String-aware comment stripping: Enhanced removeJsonComments in src/utils/web-defaults.ts with a character-by-character scanner that respects string literal boundaries and escape sequences (\", \\), ensuring // within strings is never removed.
  • Direct JSON fast-path: Attempts JSON.parse(existing) first before applying comment stripping.
  • Unit test coverage: Added tests in src/__tests__/utils/web-defaults.test.ts verifying that:
    • Strings containing // paths are preserved and parse cleanly.
    • JSON containing both valid string slashes and legitimate // or /* */ comments are parsed without corruption.

Testing

  • pnpm test passed 506/506 tests across 28 test suites (100% green).
  • pnpm run build succeeded with zero TypeScript errors.

Summary by cubic

Fixes firecrawl setup defaults failing to save web defaults when existing config files contain // inside string literals (e.g. Read(//c/Users/...)). The old regex-based comment stripper removed slashes inside strings, causing JSON syntax errors and silently skipping the save. The new string-aware scanner respects string boundaries and escape sequences, and direct JSON parse is attempted first.

Bug Fixes

  • Replaces regex comment stripping with a character-by-character scanner that tracks string state and escape sequences.
  • Tries JSON.parse on the raw content before applying comment stripping.
  • Adds tests covering strings with // paths and files mixing comments with such strings.

Written for commit 3de37f2. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Confidence score: 3/5

  • In src/utils/web-defaults.ts, lone \r line endings prevent // comments from terminating, so the scanner can discard the rest of a settings file and skip Claude defaults setup; treat \r as a line-comment terminator and add coverage for legacy line endings.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/utils/web-defaults.ts">

<violation number="1" location="src/utils/web-defaults.ts:52">
P2: When a settings file uses lone `\r` line endings, this scanner never terminates `//` comments and drops the rest of the JSON, causing Claude defaults setup to skip the file. Treat `\r` as a line-comment terminator as well as `\n`.</violation>
</file>

Heads up: you’re close to your flex budget. Increase your flex budget so reviews don’t pause.

Shadow auto-approve: would not auto-approve because issues were found.

Fix all with cubic | Re-trigger cubic

Comment thread src/utils/web-defaults.ts
const nextChar = i + 1 < content.length ? content[i + 1] : '';

if (inLineComment) {
if (char === '\n') {

@cubic-dev-ai cubic-dev-ai Bot Sep 17, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: When a settings file uses lone \r line endings, this scanner never terminates // comments and drops the rest of the JSON, causing Claude defaults setup to skip the file. Treat \r as a line-comment terminator as well as \n.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/utils/web-defaults.ts, line 52:

<comment>When a settings file uses lone `\r` line endings, this scanner never terminates `//` comments and drops the rest of the JSON, causing Claude defaults setup to skip the file. Treat `\r` as a line-comment terminator as well as `\n`.</comment>

<file context>
@@ -37,10 +37,60 @@ async function writeText(filePath: string, content: string): Promise<void> {
+    const nextChar = i + 1 < content.length ? content[i + 1] : '';
+
+    if (inLineComment) {
+      if (char === '\n') {
+        inLineComment = false;
+        result += char;
</file context>
Suggested change
if (char === '\n') {
if (char === '\n' || char === '\r') {
Fix with cubic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

setup defaults --agent claude silently skips Claude Code: JSON comment stripper corrupts // inside permission strings

1 participant