diff --git a/packages/cli/src/formatters/__tests__/__fixtures__/errors-with-special-xml-strings.json b/packages/cli/src/formatters/__tests__/__fixtures__/errors-with-special-xml-strings.json new file mode 100644 index 000000000..93aeda09f --- /dev/null +++ b/packages/cli/src/formatters/__tests__/__fixtures__/errors-with-special-xml-strings.json @@ -0,0 +1,46 @@ +[ + { + "code": "special-xml-strings", + "message": "start ' \" < > end", + "path": [ + "root", + "'", + "\"", + "leaf" + ], + "severity": 0, + "source": "", + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + } + }, + { + "code": "special-cdata-strings", + "message": "start ", + " { let parse: Parser['parseStringPromise']; @@ -69,7 +70,7 @@ describe('JUnit formatter', () => { $: { message: "should have required property '$ref'", }, - _: 'line 36, col 22, should have required property '$ref' (oas3-schema) at path #/paths/~1pets/get/responses/200/headers/header-1', + _: "line 36, col 22, should have required property '$ref' (oas3-schema) at path #/paths/~1pets/get/responses/200/headers/header-1", }, ], }, @@ -168,4 +169,56 @@ describe('JUnit formatter', () => { }, }); }); + + test('handles special XML strings properly', async () => { + const result = await parse(junit(specialXmlStrings, { failSeverity: DiagnosticSeverity.Error })); + expect(result).toEqual({ + testsuites: { + testsuite: [ + { + $: { + errors: '0', + failures: '2', + name: '', + package: 'org.spectral', + tests: '2', + time: '0', + }, + testcase: [ + { + $: { + classname: '', + name: 'org.spectral.special-xml-strings', + time: '0', + }, + failure: [ + { + $: { + message: 'start \' " < > end', + }, + _: 'line 1, col 1, start \' " < > end (special-xml-strings) at path #/root/\'/"/leaf', + }, + ], + }, + { + $: { + classname: '', + name: 'org.spectral.special-cdata-strings', + time: '0', + }, + failure: [ + { + $: { + message: 'start /', ']]]]>'); +} + export const junit: Formatter = (results, { failSeverity }) => { let output = ''; @@ -50,8 +57,8 @@ export const junit: Formatter = (results, { failSeverity }) => { output += ``; output += ''; output += ``; output += '\n';