From 812bbe9f59ec58d0410cef01e8d1530f4ad9201a Mon Sep 17 00:00:00 2001 From: Johan Hargne Date: Wed, 1 Dec 2021 14:09:41 +0100 Subject: [PATCH 1/3] Added sanitize helper method to prevent invalid XML characters to break the script --- src/htmlreporter.ts | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/htmlreporter.ts b/src/htmlreporter.ts index 59654dd..c9af83e 100644 --- a/src/htmlreporter.ts +++ b/src/htmlreporter.ts @@ -167,7 +167,7 @@ class HTMLReporter { failureMsgDiv.ele( "pre", { class: "failureMsg" }, - stripAnsi(suite.failureMessage) + this.sanitizeOutput(suite.failureMessage) ); } @@ -400,7 +400,7 @@ class HTMLReporter { failureMsgDiv.ele( "pre", { class: "failureMsg" }, - stripAnsi(failureMsg) + this.sanitizeOutput(failureMsg) ); }); } @@ -458,12 +458,12 @@ class HTMLReporter { logElement.ele( "pre", { class: "suite-consolelog-item-origin" }, - stripAnsi(log.origin) + this.sanitizeOutput(log.origin) ); logElement.ele( "pre", { class: "suite-consolelog-item-message" }, - stripAnsi(log.message) + this.sanitizeOutput(log.message) ); }); } @@ -739,6 +739,18 @@ class HTMLReporter { } return { logColor, logMsg }; // Return for testing purposes } + + /** + * Helper method to santize output from invalid characters + */ + private sanitizeOutput(input: string) { + return stripAnsi( + input.replace( + /([^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFC\u{10000}-\u{10FFFF}])/gu, + "" + ) + ); + } } export default HTMLReporter; From 48a2697bbd5439e39cf4e386c8f6a32c2a11b35a Mon Sep 17 00:00:00 2001 From: Johan Hargne Date: Wed, 1 Dec 2021 14:15:00 +0100 Subject: [PATCH 2/3] Upgraded strip-ansi --- package.json | 2 +- yarn.lock | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6f1306e..2993b8e 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "dateformat": "3.0.2", "mkdirp": "^1.0.3", "sinon": "^9.0.1", - "strip-ansi": "6.0.0", + "strip-ansi": "6.0.1", "xmlbuilder": "15.0.0" }, "peerDependencies": { diff --git a/yarn.lock b/yarn.lock index 26f8b45..56afe5b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1482,6 +1482,11 @@ ansi-regex@^5.0.0: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.0.tgz#388539f55179bf39339c81af30a654d69f87cb75" integrity sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg== +ansi-regex@^5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" + integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== + ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" @@ -3452,7 +3457,14 @@ string-width@^4.1.0, string-width@^4.2.0: is-fullwidth-code-point "^3.0.0" strip-ansi "^6.0.0" -strip-ansi@6.0.0, strip-ansi@^6.0.0: +strip-ansi@6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0: version "6.0.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532" integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w== From 40cd2c5d6411d78bf1e7c358f7a887648eac1987 Mon Sep 17 00:00:00 2001 From: Johan Hargne Date: Wed, 1 Dec 2021 14:15:43 +0100 Subject: [PATCH 3/3] Bumped version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2993b8e..b941fef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jest-html-reporter", - "version": "3.4.1", + "version": "3.4.2", "description": "Jest test results processor for generating a summary in HTML", "main": "dist/index.js", "unpkg": "dist/index.js",