Repository: mesos
Updated Branches:
  refs/heads/master 5133ddb8b -> 58e273524


Fixed JSON wrapper to properly encode bytes.

Review: https://reviews.apache.org/r/37494


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/58e27352
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/58e27352
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/58e27352

Branch: refs/heads/master
Commit: 58e273524318163684d96d618155a9d68d0de9fc
Parents: 5133ddb
Author: Vinod Kone <[email protected]>
Authored: Fri Aug 14 16:21:58 2015 -0700
Committer: Vinod Kone <[email protected]>
Committed: Fri Aug 14 19:08:27 2015 -0700

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/json.hpp       | 32 +-------------------
 .../3rdparty/stout/tests/json_tests.cpp         |  2 +-
 .../3rdparty/stout/tests/protobuf_tests.cpp     | 16 ++++++++++
 3 files changed, 18 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/58e27352/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
index 8f848ad..f28138c 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/json.hpp
@@ -496,37 +496,7 @@ inline std::ostream& operator<<(std::ostream& out, const 
String& string)
 {
   // TODO(benh): This escaping DOES NOT handle unicode, it encodes as ASCII.
   // See RFC4627 for the JSON string specificiation.
-  out << "\"";
-  foreach (unsigned char c, string.value) {
-    switch (c) {
-      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:
-        // See RFC4627 for these ranges.
-        if ((c >= 0x20 && c <= 0x21) ||
-            (c >= 0x23 && c <= 0x5B) ||
-            (c >= 0x5D && c < 0x7F)) {
-          out << c;
-        } else {
-          // NOTE: We also escape all bytes > 0x7F since they imply more than
-          // 1 byte in UTF-8. This is why we don't escape UTF-8 properly.
-          // See RFC4627 for the escaping format: \uXXXX (X is a hex digit).
-          // Each byte here will be of the form: \u00XX (this is why we need
-          // setw and the cast to unsigned int).
-          out << "\\u" << std::setfill('0') << std::setw(4)
-              << std::hex << std::uppercase << (unsigned int) c;
-        }
-        break;
-    }
-  }
-  out << "\"";
-  return out;
+  return out << picojson::value(string.value).serialize();
 }
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/58e27352/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp 
b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
index dd69209..850650c 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/json_tests.cpp
@@ -43,7 +43,7 @@ TEST(JsonTest, BinaryData)
 {
   JSON::String s(string("\"\\/\b\f\n\r\t\x00\x19 !#[]\x7F\xFF", 17));
 
-  EXPECT_EQ("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007F\\u00FF\"",
+  EXPECT_EQ("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007f\xFF\"",
             stringify(s));
 }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/58e27352/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp 
b/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp
index 018ff51..2b98945 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/protobuf_tests.cpp
@@ -23,6 +23,7 @@
 #include <stout/protobuf.hpp>
 #include <stout/stringify.hpp>
 #include <stout/strings.hpp>
+#include <stout/uuid.hpp>
 
 #include "protobuf_tests.pb.h"
 
@@ -118,4 +119,19 @@ TEST(ProtobufTest, JSON)
   ASSERT_SOME(parse);
 
   EXPECT_EQ(object, JSON::Protobuf(parse.get()));
+
+  // Modify the message to test (de-)serialization of random bytes generated
+  // by UUID.
+  message.set_bytes(UUID::random().toBytes());
+
+  object = JSON::Protobuf(message);
+
+  // Test parsing too.
+  parse = protobuf::parse<tests::Message>(object);
+  ASSERT_SOME(parse);
+
+  EXPECT_EQ(object, JSON::Protobuf(parse.get()));
+
+  // Now convert JSON to string and parse it back as JSON.
+  ASSERT_SOME_EQ(object, JSON::parse(stringify(object)));
 }

Reply via email to