The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 10:45 UTC
fix(shared): preserve JSONC properties after CR comments (#27069)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com>
Simone committed
Oct 30, 2026 at 22:23 UTC
1a7ddbef644ba2d8792c76ecb608bb733d165630
2 files changed
+22
-10
packages/shared/src/schemaJson.test.ts
+21
-9
@@ -28,18 +28,23 @@ Done.`),
28
).toBe('{"message":"literal } brace","nested":{"ok":true}}');
29
});
30
31
- it("decodes JSON with comments and trailing commas", () => {
32
- expect(
33
- decodeLenientJson(`{
31
+ it.each(["\n", "\r\n", "\r"])(
32
+ "decodes comments and trailing commas with %j line endings",
33
+ (eol) => {
34
+ expect(
35
+ decodeLenientJson(
36
+ `{
37
// Comments are valid in settings files.
38
"enabled": /* See "https://example.com/config" // still in the block */ true,
39
"values": [1, 2,],
37
- }`),
38
- ).toEqual({
39
- enabled: true,
40
- values: [1, 2],
41
- });
42
- });
40
+ }`.replaceAll("\n", eol),
41
+ ),
42
+ ).toEqual({
43
+ enabled: true,
44
+ values: [1, 2],
45
+ });
46
+ },
47
+ );
48
49
it("preserves comment markers and commas before brackets inside string values", () => {
50
expect(decodeLenientJson('"1/* https://example.com */2"')).toBe("1/* https://example.com */2");
@@ -47,4 +52,11 @@ Done.`),
52
expect(decodeLenientJson('{"list":["x,}"]}')).toEqual({ list: ["x,}"] });
53
expect(decodeLenientJson('{"values":[1, 2,],}')).toEqual({ values: [1, 2] });
54
});
55
+
56
+ it("keeps properties after CR-terminated comments in mixed line endings", () => {
57
+ expect(decodeLenientJson('{\n"enabled":true,// comment\r"values":[1,2],\n}')).toEqual({
58
+ enabled: true,
59
+ values: [1, 2],
60
+ });
61
+ });
62
});
packages/shared/src/schemaJson.ts
+1
-1
@@ -23,7 +23,7 @@ const decodeJsonString = Schema.decodeEffect(Schema.fromJsonString(Schema.Unknow
23
const parseLenientJsonGetter = SchemaGetter.transformEffect((input: string) => {
24
// Match comments together so URLs stay inside blocks; whitespace keeps adjacent tokens apart.
25
let stripped = input.replace(
26
- /("(?:[^"\\]|\\.)*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g,
26
+ /("(?:[^"\\]|\\.)*")|\/\/[^\r\n]*|\/\*[\s\S]*?\*\//g,
27
(match, stringLiteral: string | undefined) => (stringLiteral ? match : " "),
28
);
29