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

Commit 1f24262

Browse files
Andronik Ordiansorpaas
authored andcommitted
evmbin: escape newlines in json errors (#9458)
1 parent c0eb30b commit 1f24262

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

evmbin/src/display/json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl vm::Informant for Informant {
9595

9696
println!(
9797
"{{\"error\":\"{error}\",\"gasUsed\":\"{gas:x}\",\"time\":{time}}}",
98-
error = failure.error,
98+
error = display::escape_newlines(&failure.error),
9999
gas = failure.gas_used,
100100
time = display::as_micros(&failure.time),
101101
)

evmbin/src/display/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ pub fn format_time(time: &Duration) -> String {
3131
pub fn as_micros(time: &Duration) -> u64 {
3232
time.as_secs() * 1_000_000 + time.subsec_nanos() as u64 / 1_000
3333
}
34+
35+
fn escape_newlines<D: ::std::fmt::Display>(s: D) -> String {
36+
format!("{}", s).replace("\r\n", "\n").replace('\n', "\\n")
37+
}

evmbin/src/display/std_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<Trace: Writer, Out: Writer> vm::Informant for Informant<Trace, Out> {
129129
writeln!(
130130
&mut out_sink,
131131
"{{\"error\":\"{error}\",\"gasUsed\":\"0x{gas:x}\",\"time\":{time}}}",
132-
error = failure.error,
132+
error = display::escape_newlines(&failure.error),
133133
gas = failure.gas_used,
134134
time = display::as_micros(&failure.time),
135135
).expect("The sink must be writeable.");

0 commit comments

Comments
 (0)