automake2junit.ml: escape text in message of <skipped>

Escape XML characters in the logs to use as message for <skipped>, so
special characters such as &, ", and < do not make the whole XML
invalid.
This commit is contained in:
Pino Toscano
2017-03-29 15:57:40 +02:00
parent 5faa917972
commit 12c4cc7a6b

View File

@@ -108,6 +108,12 @@ let sanitize_log log =
let log = string_replace log "\x0d" "" in
log
let escape_text text =
let text = string_replace text "&" "&amp;" in
let text = string_replace text "\"" "&quot;" in
let text = string_replace text "<" "&lt;" in
text
let iterate_results trs_files =
let total = ref 0 in
let failures = ref 0 in
@@ -159,7 +165,7 @@ let iterate_results trs_files =
| Skip ->
skipped := !skipped + 1;
Buffer.add_string buf (sprintf " <testcase name=\"%s\" classname=\"%s\" time=\"%d\">\n" testname (String.concat "." (List.rev stack)) time);
Buffer.add_string buf (sprintf " <skipped message=\"%s\"></skipped>\n" log);
Buffer.add_string buf (sprintf " <skipped message=\"%s\"></skipped>\n" (escape_text log));
Buffer.add_string buf (sprintf " </testcase>\n")
| XFail | Fail | XPass ->
failures := !failures + 1;