Encode XML entities.
This commit is contained in:
parent
c3632befb5
commit
de10545906
@ -84,11 +84,13 @@ pub fn output_checkstyle_file<T>(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,
|
||||
"<error line=\"{}\" severity=\"error\" message=\"Should be \
|
||||
`{}`\" />",
|
||||
mismatch.line_number,
|
||||
str));
|
||||
message));
|
||||
}
|
||||
_ => {
|
||||
// Do nothing with context and expected.
|
||||
@ -100,6 +102,23 @@ pub fn output_checkstyle_file<T>(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<T>(writer: T,
|
||||
text: &StringBuffer,
|
||||
|
Loading…
x
Reference in New Issue
Block a user