Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Side by Side Diff: base/debug/trace_event.cc

Issue 7840017: Fix trace_event code to accept double-quote and backslash characters in string values (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/debug/trace_event_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/debug/trace_event.h" 5 #include "base/debug/trace_event.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include "base/debug/trace_event_win.h" 10 #include "base/debug/trace_event_win.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 static_cast<unsigned long long>( 80 static_cast<unsigned long long>(
81 reinterpret_cast<intptr_t>( 81 reinterpret_cast<intptr_t>(
82 as_pointer()))); 82 as_pointer())));
83 *out += temp_string; 83 *out += temp_string;
84 break; 84 break;
85 case TRACE_TYPE_STRING: 85 case TRACE_TYPE_STRING:
86 case TRACE_TYPE_STATIC_STRING: 86 case TRACE_TYPE_STATIC_STRING:
87 *out += "\""; 87 *out += "\"";
88 start_pos = out->size(); 88 start_pos = out->size();
89 *out += as_string() ? as_string() : "NULL"; 89 *out += as_string() ? as_string() : "NULL";
90 // replace " character with ' 90 // insert backslash before special characters for proper json format.
91 while ((start_pos = out->find_first_of('\"', start_pos)) != 91 while ((start_pos = out->find_first_of("\\\"", start_pos)) !=
92 std::string::npos) 92 std::string::npos) {
93 (*out)[start_pos] = '\''; 93 out->insert(start_pos, 1, '\\');
94 // skip inserted escape character and following character.
95 start_pos += 2;
96 }
94 *out += "\""; 97 *out += "\"";
95 break; 98 break;
96 default: 99 default:
97 NOTREACHED() << "Don't know how to print this value"; 100 NOTREACHED() << "Don't know how to print this value";
98 break; 101 break;
99 } 102 }
100 } 103 }
101 104
102 //////////////////////////////////////////////////////////////////////////////// 105 ////////////////////////////////////////////////////////////////////////////////
103 // 106 //
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 NULL, 0, NULL, 0, 538 NULL, 0, NULL, 0,
536 p_data_->threshold_begin_id, p_data_->threshold, 539 p_data_->threshold_begin_id, p_data_->threshold,
537 TraceLog::EVENT_FLAG_NONE); 540 TraceLog::EVENT_FLAG_NONE);
538 } 541 }
539 } 542 }
540 543
541 } // namespace internal 544 } // namespace internal
542 545
543 } // namespace debug 546 } // namespace debug
544 } // namespace base 547 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/debug/trace_event_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698