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

SH
2mo ago
+93-5

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.