File tree Expand file tree Collapse file tree
fixtures/tests/InvalidXMLCharacter Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff line change 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+ ]
You can’t perform that action at this time.
0 commit comments