fix(cicd): keep branch follower debug JSON parseable
This commit is contained in:
@@ -2862,16 +2862,39 @@ function parseJsonObject(text: string): Record<string, unknown> | null {
|
||||
const parsed = JSON.parse(trimmed) as unknown;
|
||||
return asOptionalRecord(parsed);
|
||||
} catch {
|
||||
const start = trimmed.indexOf("{");
|
||||
const end = trimmed.lastIndexOf("}");
|
||||
if (start < 0 || end <= start) return null;
|
||||
try {
|
||||
const parsed = JSON.parse(trimmed.slice(start, end + 1)) as unknown;
|
||||
return asOptionalRecord(parsed);
|
||||
} catch {
|
||||
return null;
|
||||
return parseFirstJsonObject(trimmed);
|
||||
}
|
||||
}
|
||||
|
||||
function parseFirstJsonObject(text: string): Record<string, unknown> | null {
|
||||
const start = text.indexOf("{");
|
||||
if (start < 0) return null;
|
||||
let depth = 0;
|
||||
let inString = false;
|
||||
let escaped = false;
|
||||
for (let index = start; index < text.length; index += 1) {
|
||||
const char = text[index];
|
||||
if (inString) {
|
||||
if (escaped) escaped = false;
|
||||
else if (char === "\\") escaped = true;
|
||||
else if (char === "\"") inString = false;
|
||||
continue;
|
||||
}
|
||||
if (char === "\"") inString = true;
|
||||
else if (char === "{") depth += 1;
|
||||
else if (char === "}") {
|
||||
depth -= 1;
|
||||
if (depth === 0) {
|
||||
try {
|
||||
const parsed = JSON.parse(text.slice(start, index + 1)) as unknown;
|
||||
return asOptionalRecord(parsed);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function recordAt(root: Record<string, unknown>, path: string[]): Record<string, unknown> | null {
|
||||
|
||||
Reference in New Issue
Block a user