Skip to content

Commit f92d1e6

Browse files
authored
Merge pull request #135 from Hargne/bugfix/sanitize-xml
Bugfix/sanitize xml
2 parents ed7f293 + 40cd2c5 commit f92d1e6

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-html-reporter",
3-
"version": "3.4.1",
3+
"version": "3.4.2",
44
"description": "Jest test results processor for generating a summary in HTML",
55
"main": "dist/index.js",
66
"unpkg": "dist/index.js",
@@ -51,7 +51,7 @@
5151
"dateformat": "3.0.2",
5252
"mkdirp": "^1.0.3",
5353
"sinon": "^9.0.1",
54-
"strip-ansi": "6.0.0",
54+
"strip-ansi": "6.0.1",
5555
"xmlbuilder": "15.0.0"
5656
},
5757
"peerDependencies": {

src/htmlreporter.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class HTMLReporter {
167167
failureMsgDiv.ele(
168168
"pre",
169169
{ class: "failureMsg" },
170-
stripAnsi(suite.failureMessage)
170+
this.sanitizeOutput(suite.failureMessage)
171171
);
172172
}
173173

@@ -400,7 +400,7 @@ class HTMLReporter {
400400
failureMsgDiv.ele(
401401
"pre",
402402
{ class: "failureMsg" },
403-
stripAnsi(failureMsg)
403+
this.sanitizeOutput(failureMsg)
404404
);
405405
});
406406
}
@@ -458,12 +458,12 @@ class HTMLReporter {
458458
logElement.ele(
459459
"pre",
460460
{ class: "suite-consolelog-item-origin" },
461-
stripAnsi(log.origin)
461+
this.sanitizeOutput(log.origin)
462462
);
463463
logElement.ele(
464464
"pre",
465465
{ class: "suite-consolelog-item-message" },
466-
stripAnsi(log.message)
466+
this.sanitizeOutput(log.message)
467467
);
468468
});
469469
}
@@ -739,6 +739,18 @@ class HTMLReporter {
739739
}
740740
return { logColor, logMsg }; // Return for testing purposes
741741
}
742+
743+
/**
744+
* Helper method to santize output from invalid characters
745+
*/
746+
private sanitizeOutput(input: string) {
747+
return stripAnsi(
748+
input.replace(
749+
/([^\x09\x0A\x0D\x20-\uD7FF\uE000-\uFFFC\u{10000}-\u{10FFFF}])/gu,
750+
""
751+
)
752+
);
753+
}
742754
}
743755

744756
export default HTMLReporter;

yarn.lock

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,6 +1482,11 @@ ansi-regex@^5.0.0:
14821482
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
14831483
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
14841484

1485+
ansi-regex@^5.0.1:
1486+
version "5.0.1"
1487+
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
1488+
integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==
1489+
14851490
ansi-styles@^3.2.1:
14861491
version "3.2.1"
14871492
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:
34523457
is-fullwidth-code-point "^3.0.0"
34533458
strip-ansi "^6.0.0"
34543459

3455-
[email protected], strip-ansi@^6.0.0:
3460+
3461+
version "6.0.1"
3462+
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
3463+
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
3464+
dependencies:
3465+
ansi-regex "^5.0.1"
3466+
3467+
strip-ansi@^6.0.0:
34563468
version "6.0.0"
34573469
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.0.tgz#0b1571dd7669ccd4f3e06e14ef1eed26225ae532"
34583470
integrity sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==

0 commit comments

Comments
 (0)