diff --git a/src/commands/doctor-session-sqlite-migration-run.ts b/src/commands/doctor-session-sqlite-migration-run.ts index 4400b9cbd45a..554cc0ded747 100644 --- a/src/commands/doctor-session-sqlite-migration-run.ts +++ b/src/commands/doctor-session-sqlite-migration-run.ts @@ -946,11 +946,11 @@ function renderFailureMarkdown(payload: { } function sanitizeFailureReportText(value: string): string { - return value + const sanitized = value .replace(/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g, "[redacted-email]") .replace(/(api[_-]?key|token|secret|password)[=-][A-Za-z0-9._-]+/gi, "$1-[redacted]") - .replace(/(api[_-]?key|token|secret|password)=\S+/gi, "$1=[redacted]") - .slice(0, 500); + .replace(/(api[_-]?key|token|secret|password)=\S+/gi, "$1=[redacted]"); + return truncateUtf16Safe(sanitized, 500); } function shortenFailureReportPath(filePath: string): string { diff --git a/src/commands/doctor-session-sqlite.test.ts b/src/commands/doctor-session-sqlite.test.ts index fddedcf3f7f1..471ef9e9a4a3 100644 --- a/src/commands/doctor-session-sqlite.test.ts +++ b/src/commands/doctor-session-sqlite.test.ts @@ -1566,6 +1566,8 @@ describe("runDoctorSessionSqlite", () => { it("keeps truncated GitHub issue bodies on a valid UTF-16 boundary", () => { const store = createLegacyStore(); const manifestPath = path.join(store.tempDir, "failed-migration.json"); + const unpairedSurrogate = + /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(? { const manifest: SessionSqliteMigrationManifest = { failedAt: "2030-01-01T00:00:00.000Z", @@ -1592,6 +1594,11 @@ describe("runDoctorSessionSqlite", () => { fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, { mode: 0o600 }); }; + writeManifest([`${"x".repeat(499)}🎉tail`]); + const fieldIssue = createSessionSqliteMigrationFailureIssue(manifestPath); + expect(fieldIssue?.body).not.toMatch(unpairedSurrogate); + expect(new URL(fieldIssue?.url ?? "").searchParams.get("body")).not.toContain("�"); + const baseMessages = Array.from({ length: 9 }, () => "x".repeat(500)); writeManifest([...baseMessages, "MESSAGE_START"]); const probe = createSessionSqliteMigrationFailureIssue(manifestPath); @@ -1622,9 +1629,7 @@ describe("runDoctorSessionSqlite", () => { writeManifest([`${"x".repeat(19_999 - bodyMessageOffset)}🎉tail`], bodyTargetCount); const bodyIssue = createSessionSqliteMigrationFailureIssue(manifestPath); - expect(bodyIssue?.body).not.toMatch( - /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(? {