Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing escaping to ensure generation of welformed json. #77890

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions library/test/src/formatters/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ impl<T: Write> JsonFormatter<T> {
stdout: Option<Cow<'_, str>>,
extra: Option<&str>,
) -> io::Result<()> {
// A doc test's name includes a filename which must be escaped for correct json.
self.write_message(&*format!(
r#"{{ "type": "{}", "name": "{}", "event": "{}""#,
ty, name, evt
ty,
EscapedString(name),
evt
))?;
if let Some(exec_time) = exec_time {
self.write_message(&*format!(r#", "exec_time": "{}""#, exec_time))?;
Expand All @@ -67,7 +70,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
fn write_test_start(&mut self, desc: &TestDesc) -> io::Result<()> {
self.writeln_message(&*format!(
r#"{{ "type": "test", "event": "started", "name": "{}" }}"#,
desc.name
EscapedString(desc.name.as_slice())
))
}

Expand Down Expand Up @@ -140,7 +143,10 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
\"name\": \"{}\", \
\"median\": {}, \
\"deviation\": {}{} }}",
desc.name, median, deviation, mbps
EscapedString(desc.name.as_slice()),
median,
deviation,
mbps
);

self.writeln_message(&*line)
Expand All @@ -151,7 +157,7 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
fn write_timeout(&mut self, desc: &TestDesc) -> io::Result<()> {
self.writeln_message(&*format!(
r#"{{ "type": "test", "event": "timeout", "name": "{}" }}"#,
desc.name
EscapedString(desc.name.as_slice())
))
}

Expand Down