diff options
author | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-07 00:43:11 +0000 |
---|---|---|
committer | jbates@chromium.org <jbates@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-09-07 00:43:11 +0000 |
commit | b3c8a1553bdd636deb2f390bd2fed2ba9f537097 (patch) | |
tree | 3517f7dd082e97e27a066fe9f8414de2bc7023a7 /base/debug | |
parent | 0548c535089c52b722990abf03f3df375499034d (diff) | |
download | chromium_src-b3c8a1553bdd636deb2f390bd2fed2ba9f537097.zip chromium_src-b3c8a1553bdd636deb2f390bd2fed2ba9f537097.tar.gz chromium_src-b3c8a1553bdd636deb2f390bd2fed2ba9f537097.tar.bz2 |
Fix trace_event code to accept double-quote and backslash characters in string values
BUG=95602
TEST=base_unittests
Review URL: http://codereview.chromium.org/7840017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99882 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/debug')
-rw-r--r-- | base/debug/trace_event.cc | 11 | ||||
-rw-r--r-- | base/debug/trace_event_unittest.cc | 8 |
2 files changed, 11 insertions, 8 deletions
diff --git a/base/debug/trace_event.cc b/base/debug/trace_event.cc index 8eb774e..6529592 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: diff --git a/base/debug/trace_event_unittest.cc b/base/debug/trace_event_unittest.cc index 3fbc777..839b19a 100644 --- a/base/debug/trace_event_unittest.cc +++ b/base/debug/trace_event_unittest.cc @@ -206,8 +206,8 @@ void TraceWithAllMacroVariants(WaitableEvent* task_complete_event) { TRACE_EVENT0("all", "TRACE_EVENT0 call"); TRACE_EVENT1("all", "TRACE_EVENT1 call", "name1", "value1"); TRACE_EVENT2("all", "TRACE_EVENT2 call", - "name1", "value1", - "name2", "value2"); + "name1", "\"value1\"", + "name2", "value\\2"); TRACE_EVENT_INSTANT0("all", "TRACE_EVENT_INSTANT0 call"); TRACE_EVENT_INSTANT1("all", "TRACE_EVENT_INSTANT1 call", "name1", "value1"); @@ -269,9 +269,9 @@ void ValidateAllTraceMacrosCreatedData(const ListValue& trace_parsed, EXPECT_FIND_("TRACE_EVENT1 call"); EXPECT_FIND_("TRACE_EVENT2 call"); EXPECT_SUB_FIND_("name1"); - EXPECT_SUB_FIND_("value1"); + EXPECT_SUB_FIND_("\"value1\""); EXPECT_SUB_FIND_("name2"); - EXPECT_SUB_FIND_("value2"); + EXPECT_SUB_FIND_("value\\2"); EXPECT_FIND_("TRACE_EVENT_INSTANT0 call"); EXPECT_FIND_("TRACE_EVENT_INSTANT1 call"); EXPECT_FIND_("TRACE_EVENT_INSTANT2 call"); |