Display Windows CRLF as a line break in stored script output

This commit is contained in:
2026-11-18 10:22:38 +01:00
parent a0b3aa46f5
commit 6d4f53dcae
3 changed files with 21 additions and 10 deletions
+13 -3
View File
@@ -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 = '<script>fetch("/approve")</script>\r\n\x1b[2J\u202eapprove', raw = Array.from(new TextEncoder().encode(hostile));
const hostile = '<script>fetch("/approve")</script>\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(<ConsoleOutput job={job}/>);
for (const expected of ['unknown', 'fixed-attempt', 'TIMEOUT', 'Nicht gemeldet', 'nur ein Ausschnitt', 'gespeicherte Ausgabe', 'Abbruch angefordert', 'neuen genehmigten Plan', '&lt;script&gt;', '\\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);
+5 -4
View File
@@ -27,10 +27,11 @@ export function outputText(raw: Uint8Array<ArrayBuffer>, 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<ArrayBuffer>, name: 'stdout' | 'stderr') {
const url = URL.createObjectURL(new Blob([raw], { type: 'application/octet-stream' }));
+3 -3
View File
@@ -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 && <p className="warning">{fullMaintenanceWarning}</p>}
{job.identity === 'root' && job.privilegedProfile !== fullMaintenanceScriptProfile && <p className="warning">{rootWarning}</p>}
{job.interpreter === 'powershell' && <p>Windows PowerShell 5.1 · {job.windowsProfile === windowsPowerShellRemoteSignedProfile ? 'RemoteSigned für diesen Prozess' : 'Richtlinie des Geräts'}</p>}
<pre aria-label="Vollständiger Skripttext">{outputText(new TextEncoder().encode(job.script)).text}</pre>
<pre aria-label="Vollständiger Skripttext">{visibleControls(job.script)}</pre>
{job.arguments.length > 0 && <p>Argumente <code>{JSON.stringify(job.arguments)}</code></p>}
{job.expectedStdout !== null && <p>Erwartete Ausgabe <code>{JSON.stringify(job.expectedStdout)}</code></p>}
<details><summary>Ausführungsdetails und Prüfsummen</summary>
@@ -499,7 +499,7 @@ function OrderScript({ tenantId, operation, names }: { tenantId: string; operati
return target ? deviceName(target) : job.assetId;
}).join(', ')}</h4>}
<p className="muted">{script.revision ? 'Version ' + script.revision.version : 'Einmaliges Skript'} · {script.interpreter}</p>
<pre className="script-body" aria-label="Gespeicherter Skripttext" tabIndex={0}>{outputText(new TextEncoder().encode(script.script.replace(/\r\n/g, '\n'))).text}</pre>
<pre className="script-body" aria-label="Gespeicherter Skripttext" tabIndex={0}>{visibleControls(script.script.replace(/\r\n/g, '\n'))}</pre>
</div>;
})}
</article>;