@@ -19,29 +19,52 @@ class ScoverageXmlWriter(sourceDir: File, outputDir: File, debug: Boolean) {
1919 FileUtils .write(file, new PrettyPrinter (120 , 4 ).format(xml(coverage)))
2020 }
2121
22+ /**
23+ * This method ensures that the output String has only
24+ * valid XML unicode characters as specified by the
25+ * XML 1.0 standard. For reference, please see
26+ * <a href="http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char">the
27+ * standard</a>. This method will return an empty
28+ * String if the input is null or empty.
29+ *
30+ * @param in The String whose non-valid characters we want to remove.
31+ * @return The in String, stripped of non-valid characters.
32+ * @see http://blog.mark-mclaren.info/2007/02/invalid-xml-characters-when-valid-utf8_5873.html
33+ *
34+ */
35+ private def escape (in : String ): String = {
36+ val out = new StringBuilder ()
37+ for ( current <- Option (in).getOrElse(" " ).toCharArray ) {
38+ if ((current == 0x9 ) || (current == 0xA ) || (current == 0xD ) ||
39+ ((current >= 0x20 ) && (current <= 0xD7FF )) ||
40+ ((current >= 0xE000 ) && (current <= 0xFFFD )) ||
41+ ((current >= 0x10000 ) && (current <= 0x10FFFF )))
42+ out.append(current)
43+ }
44+ out.mkString
45+ }
46+
2247 def statement (stmt : MeasuredStatement ): Node = {
2348 debug match {
24-
2549 case true =>
2650 < statement package= {stmt.location._package}
2751 class = {stmt.location._class}
2852 method= {stmt.location.method}
2953 start= {stmt.start.toString}
3054 line= {stmt.line.toString}
31- symbol= {Utility . escape(stmt.symbolName)}
55+ symbol= {escape(stmt.symbolName)}
3256 tree= {stmt.treeName}
3357 branch= {stmt.branch.toString}
3458 invocation- count= {stmt.count.toString}>
35- {Utility . escape(stmt.desc)}
59+ {escape(stmt.desc)}
3660 </statement >
37-
3861 case false =>
3962 < statement package= {stmt.location._package}
4063 class = {stmt.location._class}
4164 method= {stmt.location.method}
4265 start= {stmt.start.toString}
4366 line= {stmt.line.toString}
44- symbol= {Utility . escape(stmt.symbolName)}
67+ symbol= {escape(stmt.symbolName)}
4568 tree= {stmt.treeName}
4669 branch= {stmt.branch.toString}
4770 invocation- count= {stmt.count.toString}/>
0 commit comments