Skip to content

Commit

Permalink
Merge pull request #135 from Hargne/bugfix/sanitize-xml
Browse files Browse the repository at this point in the history
Bugfix/sanitize xml
  • Loading branch information
Hargne authored Dec 1, 2021
2 parents ed7f293 + 40cd2c5 commit f92d1e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
20 changes: 16 additions & 4 deletions src/htmlreporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class HTMLReporter {
failureMsgDiv.ele(
"pre",
{ class: "failureMsg" },
stripAnsi(suite.failureMessage)
this.sanitizeOutput(suite.failureMessage)
);
}

Expand Down Expand Up @@ -400,7 +400,7 @@ class HTMLReporter {
failureMsgDiv.ele(
"pre",
{ class: "failureMsg" },
stripAnsi(failureMsg)
this.sanitizeOutput(failureMsg)
);
});
}
Expand Down Expand Up @@ -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)
);
});
}
Expand Down Expand Up @@ -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;
14 changes: 13 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,11 @@ ansi-regex@^5.0.0:
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==

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"
Expand Down Expand Up @@ -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"

[email protected], strip-ansi@^6.0.0:
[email protected]:
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==
Expand Down

0 comments on commit f92d1e6

Please sign in to comment.