Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
evmbin: escape newlines in json errors (#9458)
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian authored and sorpaas committed Sep 4, 2018
1 parent c0eb30b commit 1f24262
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion evmbin/src/display/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl vm::Informant for Informant {

println!(
"{{\"error\":\"{error}\",\"gasUsed\":\"{gas:x}\",\"time\":{time}}}",
error = failure.error,
error = display::escape_newlines(&failure.error),
gas = failure.gas_used,
time = display::as_micros(&failure.time),
)
Expand Down
4 changes: 4 additions & 0 deletions evmbin/src/display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ pub fn format_time(time: &Duration) -> String {
pub fn as_micros(time: &Duration) -> u64 {
time.as_secs() * 1_000_000 + time.subsec_nanos() as u64 / 1_000
}

fn escape_newlines<D: ::std::fmt::Display>(s: D) -> String {
format!("{}", s).replace("\r\n", "\n").replace('\n', "\\n")
}
2 changes: 1 addition & 1 deletion evmbin/src/display/std_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl<Trace: Writer, Out: Writer> vm::Informant for Informant<Trace, Out> {
writeln!(
&mut out_sink,
"{{\"error\":\"{error}\",\"gasUsed\":\"0x{gas:x}\",\"time\":{time}}}",
error = failure.error,
error = display::escape_newlines(&failure.error),
gas = failure.gas_used,
time = display::as_micros(&failure.time),
).expect("The sink must be writeable.");
Expand Down

0 comments on commit 1f24262

Please sign in to comment.