From 89f75263c5f89393efce8a7ac502364c4923d1b6 Mon Sep 17 00:00:00 2001 From: Shakker Date: Tue, 5 May 2026 08:43:35 +0100 Subject: [PATCH] fix: avoid control regex in handoff diagnostics --- src/infra/restart-handoff.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/infra/restart-handoff.ts b/src/infra/restart-handoff.ts index c3f5d228b3e..af0c31bb754 100644 --- a/src/infra/restart-handoff.ts +++ b/src/infra/restart-handoff.ts @@ -54,10 +54,21 @@ function formatShortDuration(ms: number): string { } function formatDiagnosticValue(value: string): string { - return value - .replace(/[\u0000-\u001f\u007f]+/gu, " ") - .replace(/\s+/gu, " ") - .trim(); + let normalized = ""; + let previousWasSpace = true; + for (const char of value) { + const code = char.charCodeAt(0); + if (code <= 0x1f || code === 0x7f || /\s/u.test(char)) { + if (!previousWasSpace) { + normalized += " "; + previousWasSpace = true; + } + continue; + } + normalized += char; + previousWasSpace = false; + } + return normalized.trimEnd(); } export function formatGatewayRestartHandoffDiagnostic(