The best way to control Claude Code, Codex and more from any computer or phone
fix(shared): read JSONC block comments containing URLs (#19166)
Co-authored-by: Simone <185146821+Lucenx9@users.noreply.github.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Simone committed
Oct 19, 2026 at 22:19 UTC
346049725edd7f7ddb4abf62c8e27792ae8bed53
3 files changed
+14
-13
packages/shared/src/schemaJson.test.ts
+4
-2
@@ -44,7 +44,7 @@ Done.`),
44
expect(
45
decodeLenientJson(`{
46
// Comments are valid in settings files.
47
- "enabled": true,
47
+ "enabled": /* See "https://example.com/config" // still in the block */ true,
48
"values": [1, 2,],
49
}`),
50
).toEqual({
@@ -55,9 +55,11 @@ Done.`),
55
56
it("rejects malformed JSON after lenient preprocessing", () => {
57
expect(() => decodeLenientJson('{ "enabled": true,, }')).toThrow();
58
+ expect(() => decodeLenientJson("[1/* https://example.com */2]")).toThrow();
59
});
60
60
- it("preserves commas before brackets inside string values", () => {
61
+ it("preserves comment markers and commas before brackets inside string values", () => {
62
+ expect(decodeLenientJson('"1/* https://example.com */2"')).toBe("1/* https://example.com */2");
63
expect(decodeLenientJson('{"note":"a,]"}')).toEqual({ note: "a,]" });
64
expect(decodeLenientJson('{"list":["x,}"]}')).toEqual({ list: ["x,}"] });
65
expect(decodeLenientJson('{"values":[1, 2,],}')).toEqual({ values: [1, 2] });
packages/shared/src/schemaJson.ts
+3
-7
@@ -158,14 +158,10 @@ export const formatSchemaError = (cause: Cause.Cause<Schema.SchemaError>) => {
158
const decodeJsonString = Schema.decodeEffect(Schema.fromJsonString(Schema.Unknown));
159
160
const parseLenientJsonGetter = SchemaGetter.transformEffect((input: string) => {
161
+ // Match comments together so URLs stay inside blocks; whitespace keeps adjacent tokens apart.
162
let stripped = input.replace(
162
- /("(?:[^"\\]|\\.)*")|\/\/[^\n]*/g,
163
- (match, stringLiteral: string | undefined) => (stringLiteral ? match : ""),
164
- );
165
-
166
- stripped = stripped.replace(
167
- /("(?:[^"\\]|\\.)*")|\/\*[\s\S]*?\*\//g,
168
- (match, stringLiteral: string | undefined) => (stringLiteral ? match : ""),
163
+ /("(?:[^"\\]|\\.)*")|\/\/[^\n]*|\/\*[\s\S]*?\*\//g,
164
+ (match, stringLiteral: string | undefined) => (stringLiteral ? match : " "),
165
);
166
167
stripped = stripped.replace(
packages/shared/src/t3ProjectFile.test.ts
+7
-4
@@ -82,10 +82,13 @@ describe("T3ProjectFileFromJson", () => {
82
});
83
84
describe("parseT3ProjectFile", () => {
85
- it("returns the decoded file for valid contents", () => {
86
- expect(parseT3ProjectFile('{ "defaultThreadEnvMode": "worktree" }')).toEqual({
87
- defaultThreadEnvMode: "worktree",
88
- });
85
+ it("reads project defaults from JSONC with a URL in a block comment", () => {
86
+ expect(
87
+ parseT3ProjectFile(`{
88
+ /* See https://t3.codes/schema/t3.json */
89
+ "defaultThreadEnvMode": "worktree"
90
+ }`),
91
+ ).toEqual({ defaultThreadEnvMode: "worktree" });
92
});
93
94
it("returns null for malformed or invalid contents", () => {