From f6fcc0f70b4a4530b667345068ec3a8eba167c87 Mon Sep 17 00:00:00 2001 From: Markus Dobmann Date: Tue, 4 Jul 2023 10:06:40 +0200 Subject: [PATCH] fix unit tests for `sanitizeSectionContent` --- client/lib/plugins/malformed-html-fixtures.js | 18 ++++++------------ .../plugins/test/sanitize-section-content.js | 8 +++----- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/client/lib/plugins/malformed-html-fixtures.js b/client/lib/plugins/malformed-html-fixtures.js index 510d1198d1473..36c30584326a2 100644 --- a/client/lib/plugins/malformed-html-fixtures.js +++ b/client/lib/plugins/malformed-html-fixtures.js @@ -954,32 +954,27 @@ export default [ title: 'Tests against mXSS behavior with SVG in Chrome 77 and alike 1/2', payload: '

', - expected: '

</textarea><img src=x onerror=alert(1)>', - expectedSSR: '

<title><style>', + expected: '

<title><style>', }, { title: 'Tests against mXSS behavior with SVG in Chrome 77 and alike 2/2', payload: '

', - expected: '

', - expectedSSR: '

<a id="">', + expected: '

<a id="">', }, { title: 'Tests against mXSS behavior with MathML in Chrome 77 and alike', payload: '

', - expected: '

<img src=x onerror=alert(1)>', - expectedSSR: '

', + expected: '

', }, { title: 'Tests against attribute-based mXSS behavior 1/3', diff --git a/client/lib/plugins/test/sanitize-section-content.js b/client/lib/plugins/test/sanitize-section-content.js index 1769310f944b6..c5d9adfab5fa1 100644 --- a/client/lib/plugins/test/sanitize-section-content.js +++ b/client/lib/plugins/test/sanitize-section-content.js @@ -219,11 +219,9 @@ const runTests = ( isSSR = false ) => { ); } ); - fixtures.forEach( ( { title, payload, expected, expectedSSR }, index ) => { - test( `Fixture test #${ index }: ${ title } `, () => { - const toBeExpected = isSSR ? expectedSSR || expected : expected; - expect( clean( payload ) ).toBe( toBeExpected ); - } ); + test.each( fixtures )( '`Fixture test $#: $title `', ( testConfig ) => { + const { payload, expected } = testConfig; + expect( clean( payload ) ).toBe( expected ); } ); };