diff --git a/web/src/console-output.test.tsx b/web/src/console-output.test.tsx index 1a8ef09..728ade2 100644 --- a/web/src/console-output.test.tsx +++ b/web/src/console-output.test.tsx @@ -6,7 +6,7 @@ import { ConsoleOutput, outputBytes, outputText } from './console-output'; it('renders hostile output as inert text, reports real status and preserves exact raw bytes', () => { const fetch = vi.fn(); vi.stubGlobal('fetch', fetch); try { - const hostile = '\r\n\x1b[2J\u202eapprove', raw = Array.from(new TextEncoder().encode(hostile)); + const hostile = '\r\r\n\x1b[2J\u202eapprove', raw = Array.from(new TextEncoder().encode(hostile)); const job = { state: 'unknown', attempt_id: 'fixed-attempt', revision: 4, cancel_requested: true, result: { stdout: raw, stderr: [], exit_code: null, error_code: 'TIMEOUT', output_truncated: true, reboot_required: false } }; const before = JSON.stringify(job), html = renderToStaticMarkup(); for (const expected of ['unknown', 'fixed-attempt', 'TIMEOUT', 'Nicht gemeldet', 'nur ein Ausschnitt', 'gespeicherte Ausgabe', 'Abbruch angefordert', 'neuen genehmigten Plan', '<script>', '\\u000d', '\\u001b', '\\u202e', JSON.stringify(raw)]) expect(html).toContain(expected); @@ -24,7 +24,7 @@ it('distinguishes no result, empty bytes, invalid encoding, invalid bytes and mi expect(bad.match(/Keine verlässliche Textansicht/g)).toHaveLength(2); for (const raw of [undefined, 'hello', [1.5], [-1], [256]]) expect(() => outputBytes(raw)).toThrow(); const bytes = outputBytes([239, 187, 191, 65, 13, 10]); - expect(outputText(bytes).text).toBe('\\ufeffA\\u000d\n'); expect(Array.from(bytes)).toEqual([239, 187, 191, 65, 13, 10]); + expect(outputText(bytes).text).toBe('\\ufeffA\n'); expect(Array.from(bytes)).toEqual([239, 187, 191, 65, 13, 10]); }); it('shows unknown restart state for an incomplete Windows Update summary', () => { @@ -42,7 +42,7 @@ it('shows unknown restart state for an incomplete Windows Update summary', () => it('decodes native PowerShell CP850 umlauts while preserving raw bytes and control escapes', () => { const raw = outputBytes([132, 148, 129, 142, 153, 154, 225, 13, 10, 27]); const original = Array.from(raw); - expect(outputText(raw, 'powershell').text).toBe('äöüÄÖÜß\\u000d\n\\u001b'); + expect(outputText(raw, 'powershell').text).toBe('äöüÄÖÜß\n\\u001b'); expect(outputText(raw, 'powershell').encoding).toContain('Quellcodepage nicht separat belegt'); expect(outputText(raw, 'utf-8').text).toContain('�'); expect(Array.from(raw)).toEqual(original); @@ -55,6 +55,16 @@ it('keeps valid UTF-8 PowerShell output and generic invalid UTF-8 on their exist expect(outputText(outputBytes([148])).text).toBe('�'); }); +it('renders CRLF lines in UTF-8 and CP850 with standalone carriage returns visible', () => { + const utf8 = Array.from(new TextEncoder().encode('Grüße\r\n\r\nOK\rEnde\r\n')); + const cp850 = [71, 114, 129, 225, 101, 13, 10, 13, 10, 79, 75, 13, 69, 110, 100, 101, 13, 10]; + for (const bytes of [utf8, cp850]) { + const raw = outputBytes(bytes); + expect(outputText(raw, 'powershell').text).toBe('Grüße\n\nOK\\u000dEnde\n'); + expect(Array.from(raw)).toEqual(bytes); + } +}); + it('selects the native PowerShell text view only from matching result evidence', () => { const result = { stdout: [98, 148, 115, 97, 114, 116, 105, 103], stderr: [], evidence: {interpreter:'powershell',output_encoding:'raw_native_bytes'} }; const before = JSON.stringify(result); diff --git a/web/src/console-output.tsx b/web/src/console-output.tsx index 25250aa..925c096 100644 --- a/web/src/console-output.tsx +++ b/web/src/console-output.tsx @@ -27,10 +27,11 @@ export function outputText(raw: Uint8Array, selected: OutputEncodin } } } - // Make terminal/control and bidi characters visible. In particular CR cannot - // visually overwrite an earlier line; CRLF remains recognizable as such. - return { text: decoded.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, - char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`), encoding }; + return { text: visibleControls(decoded.replaceAll('\r\n', '\n')), encoding }; +} +export function visibleControls(text: string): string { + return text.replace(/[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069\ufeff]/g, + char => `\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`); } function download(raw: Uint8Array, name: 'stdout' | 'stderr') { const url = URL.createObjectURL(new Blob([raw], { type: 'application/octet-stream' })); diff --git a/web/src/main.tsx b/web/src/main.tsx index 901a08b..d2ff000 100644 --- a/web/src/main.tsx +++ b/web/src/main.tsx @@ -14,7 +14,7 @@ import './style.css'; import { AdminControl, Catalog, TenantControls } from './management'; import { allowed, availableActions, parseStrictJson, powerShellApprovalBlockers, powerShellPlanJobs, rootWarning, systemWarning, systemPlanJobs, validateSensitiveInput, verifyPlanIntegrity, queryLogsApprovalBlockers, queryLogsPlanJobs, windowsMsiApprovalBlockers, windowsMsiPlanJobs, verifyWindowsMsiManifest, fullMaintenanceWarning } from './safety'; import { Login } from './login'; -import { ConsoleOutput, outputText } from './console-output'; +import { ConsoleOutput, visibleControls } from './console-output'; import { scriptApprovalBlockers, scriptPlanJobs, verifyScriptPlan } from './script-console'; import { agentUpdateWarning, agentUpdatePlanJobs, agentUpdateApprovalBlockers, verifyAgentUpdatePlan, verifyReleaseMetadata, releaseEnvelope, uploadAgentUpdateArtifact } from './agent-updates'; @@ -56,7 +56,7 @@ export function ScriptPlanNotice({ plan }: { plan: RecordValue }) { {job.privilegedProfile === fullMaintenanceScriptProfile &&

{fullMaintenanceWarning}

} {job.identity === 'root' && job.privilegedProfile !== fullMaintenanceScriptProfile &&

{rootWarning}

} {job.interpreter === 'powershell' &&

Windows PowerShell 5.1 · {job.windowsProfile === windowsPowerShellRemoteSignedProfile ? 'RemoteSigned für diesen Prozess' : 'Richtlinie des Geräts'}

} -
{outputText(new TextEncoder().encode(job.script)).text}
+
{visibleControls(job.script)}
{job.arguments.length > 0 &&

Argumente {JSON.stringify(job.arguments)}

} {job.expectedStdout !== null &&

Erwartete Ausgabe {JSON.stringify(job.expectedStdout)}

}
Ausführungsdetails und Prüfsummen @@ -499,7 +499,7 @@ function OrderScript({ tenantId, operation, names }: { tenantId: string; operati return target ? deviceName(target) : job.assetId; }).join(', ')}}

{script.revision ? 'Version ' + script.revision.version : 'Einmaliges Skript'} · {script.interpreter}

-
{outputText(new TextEncoder().encode(script.script.replace(/\r\n/g, '\n'))).text}
+
{visibleControls(script.script.replace(/\r\n/g, '\n'))}
; })} ;