You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/05/14 23:20:16 UTC
svn commit: r1338430 - /incubator/mesos/trunk/src/common/json.hpp
Author: benh
Date: Mon May 14 21:20:15 2012
New Revision: 1338430
URL: http://svn.apache.org/viewvc?rev=1338430&view=rev
Log:
Properly escaping JSON (except for unicode) (https://reviews.apache.org/r/5104).
Modified:
incubator/mesos/trunk/src/common/json.hpp
Modified: incubator/mesos/trunk/src/common/json.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/common/json.hpp?rev=1338430&r1=1338429&r2=1338430&view=diff
==============================================================================
--- incubator/mesos/trunk/src/common/json.hpp (original)
+++ incubator/mesos/trunk/src/common/json.hpp Mon May 14 21:20:15 2012
@@ -108,7 +108,24 @@ struct Renderer : boost::static_visitor<
void operator () (const String& string) const
{
- out << "\"" << string.value << "\"";
+ // TODO(benh): This escaping DOES NOT handle unicode.
+ out << "\"";
+ std::string::const_iterator iterator = string.value.begin();
+ while (iterator != string.value.end()) {
+ switch (*iterator) {
+ case '"': out << "\\\""; break;
+ case '\\': out << "\\\\"; break;
+ case '/': out << "\\/"; break;
+ case '\b': out << "\\b"; break;
+ case '\f': out << "\\f"; break;
+ case '\n': out << "\\n"; break;
+ case '\r': out << "\\r"; break;
+ case '\t': out << "\\t"; break;
+ default: out << *iterator; break;
+ }
+ ++iterator;
+ }
+ out << "\"";
}
void operator () (const Number& number) const