fix(web-defaults): safely parse JSON with strings containing slashes …
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
removeJsonCommentsinsrc/utils/web-defaults.tswith 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.tsverifying that:- Strings containing
//paths are preserved and parse cleanly. - JSON containing both valid string slashes and legitimate
//or/* */comments are parsed without corruption.
- Strings containing
Testing
pnpm testpassed 506/506 tests across 28 test suites (100% green).pnpm run buildsucceeded 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.parseon the raw content before applying comment stripping. - Adds tests covering strings with
//paths and files mixing comments with such strings.