fix(json-formatter): auto fix destroys text in single-quoted strings #31

Open
opened 2026-10-28 21:52:10 +00:00 by flopana · 0 comments
Owner

Part of #30

Branch: feature/improve-json-formatter

Bugs

Auto fix in src/lib/jsonFixer.ts reads " strings only. JsonFormatterComponent.tsx writes the result back into the input, so bug 1 destroys user text.

Input Output now
{'url': 'http://example.com'} {"url": 'http: (the rest is gone)
{'a': 'say "hi"'} {"a": 'say "hi"'} (invalid)
{'a': 'it\'s'} {"a": "it\"s'} (invalid)
{"a": 1 // say "x + newline + } {"a": 1 "x + newline + } (invalid)

Verification: the review agent reproduced all 4 in node.

Red tests

Add the 4 inputs to src/lib/jsonFixer.test.ts. Expected: valid JSON with no data loss.

Fix

Replace the passes with one scanner. It reads " strings, ' strings with escapes, // comments and /* */ comments in one pass. It changes only text outside strings. The existing tests stay green.

Also in scope

  • Whitespace-only input shows the red badge but no fix button. Use trim() in both checks.
Part of #30 Branch: `feature/improve-json-formatter` ## Bugs Auto fix in `src/lib/jsonFixer.ts` reads `"` strings only. `JsonFormatterComponent.tsx` writes the result back into the input, so bug 1 destroys user text. | Input | Output now | |---|---| | `{'url': 'http://example.com'}` | `{"url": 'http:` (the rest is gone) | | `{'a': 'say "hi"'}` | `{"a": 'say "hi"'}` (invalid) | | `{'a': 'it\'s'}` | `{"a": "it\"s'}` (invalid) | | `{"a": 1 // say "x` + newline + `}` | `{"a": 1 "x` + newline + `}` (invalid) | Verification: the review agent reproduced all 4 in node. ## Red tests Add the 4 inputs to `src/lib/jsonFixer.test.ts`. Expected: valid JSON with no data loss. ## Fix Replace the passes with one scanner. It reads `"` strings, `'` strings with escapes, `//` comments and `/* */` comments in one pass. It changes only text outside strings. The existing tests stay green. ## Also in scope - Whitespace-only input shows the red badge but no fix button. Use `trim()` in both checks.
Sign in to join this conversation.
No description provided.