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

evmbin: escape newlines in json errors #9458

Merged
Merged
Show file tree
Hide file tree
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
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