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);