about summary refs log tree commit diff
path: root/src/filemap.rs
diff options
context:
space:
mode:
authorMark Story <mark@mark-story.com>2016-01-03 23:17:49 -0500
committerMark Story <mark@mark-story.com>2016-01-13 21:02:50 -0500
commitde10545906899084162b6511f15771db491551cc (patch)
tree9ab4a879c4f075395f89037a77a1fe3f3fdb246a /src/filemap.rs
parentc3632befb5f733a1a0cd8f42c6d0b8dbca100680 (diff)
Encode XML entities.
Diffstat (limited to 'src/filemap.rs')
-rw-r--r--src/filemap.rs21
1 files changed, 20 insertions, 1 deletions
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<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("&lt;"),
+            '>' => out.push_str("&gt;"),
+            '"' => out.push_str("&quot;"),
+            '\'' => out.push_str("&apos;"),
+            '&' => out.push_str("&amp;"),
+            _ => out.push(c),
+        }
+    }
+    out
+}
+
 // Prints all newlines either as `\n` or as `\r\n`.
 pub fn write_system_newlines<T>(writer: T,
                                 text: &StringBuffer,