Index: base/debug/trace_event.cc |
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc |
index 8eb774e5b5cebd74f82770a1539086d21f54b5f6..6529592628da5f20e6d3b03ff10cc68d04464026 100644 |
--- a/base/debug/trace_event.cc |
+++ b/base/debug/trace_event.cc |
@@ -87,10 +87,13 @@ void TraceValue::AppendAsJSON(std::string* out) const { |
*out += "\""; |
start_pos = out->size(); |
*out += as_string() ? as_string() : "NULL"; |
- // replace " character with ' |
- while ((start_pos = out->find_first_of('\"', start_pos)) != |
- std::string::npos) |
- (*out)[start_pos] = '\''; |
+ // insert backslash before special characters for proper json format. |
+ while ((start_pos = out->find_first_of("\\\"", start_pos)) != |
+ std::string::npos) { |
+ out->insert(start_pos, 1, '\\'); |
+ // skip inserted escape character and following character. |
+ start_pos += 2; |
+ } |
*out += "\""; |
break; |
default: |