From ffc47271f2127035f1605ead7dce2b1e2ff6b1d8 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 25 Oct 2022 14:39:16 -0700 Subject: [PATCH] fix(junit): escape null control character (#18325) Fixes https://github.com/microsoft/playwright/issues/18322 --- packages/playwright-test/src/reporters/junit.ts | 2 +- tests/playwright-test/reporter-junit.spec.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/playwright-test/src/reporters/junit.ts b/packages/playwright-test/src/reporters/junit.ts index b8e74ab16d..4dc1076276 100644 --- a/packages/playwright-test/src/reporters/junit.ts +++ b/packages/playwright-test/src/reporters/junit.ts @@ -285,7 +285,7 @@ function serializeXML(entry: XMLEntry, tokens: string[], stripANSIControlSequenc } // See https://en.wikipedia.org/wiki/Valid_characters_in_XML -const discouragedXMLCharacters = /[\u0001-\u0008\u000b-\u000c\u000e-\u001f\u007f-\u0084\u0086-\u009f]/g; +const discouragedXMLCharacters = /[\u0000-\u0008\u000b-\u000c\u000e-\u001f\u007f-\u0084\u0086-\u009f]/g; function escape(text: string, stripANSIControlSequences: boolean, isCharacterData: boolean): string { if (stripANSIControlSequences) diff --git a/tests/playwright-test/reporter-junit.spec.ts b/tests/playwright-test/reporter-junit.spec.ts index 754661fe67..2116055fb6 100644 --- a/tests/playwright-test/reporter-junit.spec.ts +++ b/tests/playwright-test/reporter-junit.spec.ts @@ -106,6 +106,7 @@ test('should render stdout', async ({ runInlineTest }) => { console.log(colors.yellow('Hello world')); console.log('Hello again'); console.error('My error'); + console.error('\\0'); // null control character test.expect("abc").toBe('abcd'); }); `, @@ -116,7 +117,8 @@ test('should render stdout', async ({ runInlineTest }) => { expect(testcase['system-out'][0]).toContain('[33mHello world[39m\nHello again'); expect(testcase['system-out'][0]).not.toContain('u00'); expect(testcase['system-err'][0]).toContain('My error'); - expect(testcase['failure'][0]['_']).toContain(`> 11 | test.expect("abc").toBe('abcd');`); + expect(testcase['system-err'][0]).not.toContain('\u0000'); // null control character + expect(testcase['failure'][0]['_']).toContain(`> 12 | test.expect("abc").toBe('abcd');`); expect(result.exitCode).toBe(1); });