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

Unified Diff: runtime/vm/json_stream.cc

Issue 22599002: Escape strings when writing to JSON. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/json_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/json_stream.cc
diff --git a/runtime/vm/json_stream.cc b/runtime/vm/json_stream.cc
index b3a61d36c62a8841e9cc365a82aabe8f9c74b976..1aec0bcd766d0c36628be6f72b00d7b733d6f9c1 100644
--- a/runtime/vm/json_stream.cc
+++ b/runtime/vm/json_stream.cc
@@ -85,7 +85,9 @@ void JSONStream::PrintValue(double d) {
void JSONStream::PrintValue(const char* s) {
PrintCommaIfNeeded();
- buffer_->Printf("\"%s\"", s);
+ buffer_->AddChar('"');
+ buffer_->AddEscapedString(s);
+ buffer_->AddChar('"');
}
@@ -101,7 +103,9 @@ void JSONStream::PrintfValue(const char* format, ...) {
intptr_t len2 = OS::VSNPrint(p, len+1, format, args);
va_end(args);
ASSERT(len == len2);
- buffer_->Printf("\"%s\"", p);
+ buffer_->AddChar('"');
+ buffer_->AddEscapedString(p);
+ buffer_->AddChar('"');
free(p);
}
@@ -147,7 +151,9 @@ void JSONStream::PrintfProperty(const char* name, const char* format, ...) {
intptr_t len2 = OS::VSNPrint(p, len+1, format, args);
va_end(args);
ASSERT(len == len2);
- buffer_->Printf("\"%s\"", p);
+ buffer_->AddChar('"');
+ buffer_->AddEscapedString(p);
+ buffer_->AddChar('"');
free(p);
}
@@ -176,7 +182,10 @@ void JSONStream::PrintProperty(const char* name, const Object& o, bool ref) {
void JSONStream::PrintPropertyName(const char* name) {
ASSERT(name != NULL);
PrintCommaIfNeeded();
- buffer_->Printf("\"%s\":", name);
+ buffer_->AddChar('"');
+ buffer_->AddEscapedString(name);
+ buffer_->AddChar('"');
+ buffer_->AddChar(':');
}
« no previous file with comments | « no previous file | runtime/vm/json_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698