diff --git a/src/filemap.rs b/src/filemap.rs index f9e927f03b2..212b95dd25b 100644 --- a/src/filemap.rs +++ b/src/filemap.rs @@ -84,11 +84,13 @@ pub fn output_checkstyle_file(mut writer: T, for line in mismatch.lines { match line { DiffLine::Expected(ref str) => { + let message = xml_escape_str(&str); + // TODO XML encode str here. try!(write!(writer, "", mismatch.line_number, - str)); + message)); } _ => { // Do nothing with context and expected. @@ -100,6 +102,23 @@ pub fn output_checkstyle_file(mut writer: T, Ok(()) } +// Convert special characters into XML entities. +// This is needed for checkstyle output. +fn xml_escape_str(string: &str) -> String { + let mut out = String::new(); + for c in string.chars() { + match c { + '<' => out.push_str("<"), + '>' => out.push_str(">"), + '"' => out.push_str("""), + '\'' => out.push_str("'"), + '&' => out.push_str("&"), + _ => out.push(c), + } + } + out +} + // Prints all newlines either as `\n` or as `\r\n`. pub fn write_system_newlines(writer: T, text: &StringBuffer,