Encode XML entities.
This commit is contained in:
parent
c3632befb5
commit
de10545906
1 changed files with 20 additions and 1 deletions
|
@ -84,11 +84,13 @@ pub fn output_checkstyle_file<T>(mut writer: T,
|
||||||
for line in mismatch.lines {
|
for line in mismatch.lines {
|
||||||
match line {
|
match line {
|
||||||
DiffLine::Expected(ref str) => {
|
DiffLine::Expected(ref str) => {
|
||||||
|
let message = xml_escape_str(&str);
|
||||||
|
// TODO XML encode str here.
|
||||||
try!(write!(writer,
|
try!(write!(writer,
|
||||||
"<error line=\"{}\" severity=\"error\" message=\"Should be \
|
"<error line=\"{}\" severity=\"error\" message=\"Should be \
|
||||||
`{}`\" />",
|
`{}`\" />",
|
||||||
mismatch.line_number,
|
mismatch.line_number,
|
||||||
str));
|
message));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// Do nothing with context and expected.
|
// Do nothing with context and expected.
|
||||||
|
@ -100,6 +102,23 @@ pub fn output_checkstyle_file<T>(mut writer: T,
|
||||||
Ok(())
|
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`.
|
// Prints all newlines either as `\n` or as `\r\n`.
|
||||||
pub fn write_system_newlines<T>(writer: T,
|
pub fn write_system_newlines<T>(writer: T,
|
||||||
text: &StringBuffer,
|
text: &StringBuffer,
|
||||||
|
|
Loading…
Reference in a new issue