Skip to content

Commit cc5779d

Browse files
authored
fix: escape XML in error stack trace when using junit reporter (#3038)
1 parent a768015 commit cc5779d

File tree

5 files changed

+6
-4
lines changed

5 files changed

+6
-4
lines changed

packages/vitest/src/node/reporters/junit.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export class JUnitReporter implements Reporter {
131131
for (const frame of stack) {
132132
const path = relative(this.ctx.config.root, frame.file)
133133

134-
await this.baseLog(` ${F_POINTER} ${[frame.method, `${path}:${frame.line}:${frame.column}`].filter(Boolean).join(' ')}`)
134+
await this.baseLog(escapeXML(` ${F_POINTER} ${[frame.method, `${path}:${frame.line}:${frame.column}`].filter(Boolean).join(' ')}`))
135135

136136
// reached at test file, skip the follow stack
137137
if (frame.file in this.ctx.state.filesMap)

test/reporters/src/data-for-junit.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function createSuiteHavingFailedTestWithXmlInError(): File[] {
2828

2929
errorWithXml.stack = 'Error: error message that has XML in it <tag>\n'
3030
+ ' at /vitest/test/core/test/basic.test.ts:8:32\n'
31+
+ ' at /vitest/test/core/test/<bracket-name>.ts:3:11\n'
3132
+ ' at etc....'
3233

3334
const tasks: Task[] = [

test/reporters/tests/__snapshots__/html.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Vitest Snapshot v1
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`html reporter > resolves to "failing" status for test file "json-fail" > tests are failing 1`] = `
44
{

test/reporters/tests/__snapshots__/json.test.ts.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Vitest Snapshot v1
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`json reporter > generates correct report 1`] = `
44
{

test/reporters/tests/__snapshots__/reporters.spec.ts.snap

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Vitest Snapshot v1
1+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`JUnit reporter (no outputFile entry) 1`] = `
44
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" ?>
@@ -249,6 +249,7 @@ exports[`JUnit reporter with outputFile with XML in error message 2`] = `
249249
<failure message=\\"error message that has XML in it &lt;tag&gt;\\" type=\\"AssertionError\\">
250250
AssertionError: error message that has XML in it &lt;tag&gt;
251251
test/core/test/basic.test.ts:8:32
252+
test/core/test/&lt;bracket-name&gt;.ts:3:11
252253
</failure>
253254
</testcase>
254255
</testsuite>

0 commit comments

Comments
 (0)