Skip to content

Commit a9f85eb

Browse files
authored
Merge pull request #625 from NoRedInk/junit-strip-invalid-characters
Junit replace invalid characters
2 parents 9c4ffdc + b6d5d8d commit a9f85eb

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

lib/Supervisor.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,27 @@ function run(
201201

202202
xml.testsuite.testcase = xml.testsuite.testcase.concat(values);
203203

204-
console.log(XmlBuilder.create(xml).end());
204+
// The XmlBuilder by default does not remove characters that are
205+
// invalid in XML, like backspaces. However, we can pass it an
206+
// `invalidCharReplacement` option to tell it how to handle
207+
// those characters, rather than crashing. In an attempt to
208+
// retain useful information in the output, we try and output a
209+
// hex-encoded unicode codepoint for the invalid character. For
210+
// example, the start of a terminal escape (`\u{001B}` in Elm) will be output as a
211+
// literal `\u{001B}`.
212+
var invalidCharReplacement = function (char) {
213+
return (
214+
'\\u{' +
215+
char.codePointAt(0).toString(16).padStart(4, '0') +
216+
'}'
217+
);
218+
};
219+
220+
console.log(
221+
XmlBuilder.create(xml, {
222+
invalidCharReplacement: invalidCharReplacement,
223+
}).end()
224+
);
205225
}
206226
}
207227

tests/ci.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ describe('Testing elm-test on single Elm files', () => {
292292
}
293293
}
294294

295+
it(`Should not crash the junit reporter on invalid characters`, () => {
296+
const itsPath = path.join('tests', 'InvalidXMLCharacter', 'Test.elm');
297+
const runResult = execElmTest([itsPath, '--report', 'junit'], cwd);
298+
assertTestSuccess(runResult);
299+
});
300+
295301
it(`Should run every file in tests/CompileError`, () => {
296302
const filesFound = readdir(path.join(cwd, 'tests', 'CompileError'));
297303
assert.deepStrictEqual(
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module InvalidXMLCharacter.Test exposing (invalidCharacter)
2+
3+
import Expect
4+
import Test exposing (..)
5+
6+
7+
invalidCharacter : Test
8+
invalidCharacter =
9+
describe "The junit reporter should not crash due to invalid (for XML) characters in the output"
10+
[ test "backspace: \u{0008}" <|
11+
\() -> Expect.pass
12+
, test "escape: \u{001B}" <|
13+
\() -> Expect.pass
14+
]

0 commit comments

Comments
 (0)