You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2018/07/25 03:24:22 UTC

[06/10] mesos git commit: Fixed issues with the JSON serialization tests.

Fixed issues with the JSON serialization tests.

There were some issues in the existing JSON serialization tests
when it comes to rapidjson. For example:

  - 0x7F does not need to be escaped per ECMA-404. This is what
    rapidjson adheres to.
  - Forward slash does not need to be escaped.

This updates the test to have a valid UTF-8 case with a multi-byte
sequence (which does not need to be escaped per ECMA-404), as well
as an invalid case where a multibyte sequence is partial (which we
allow for now since we do not have validation errors exposed).

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


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

Branch: refs/heads/master
Commit: 97420515f6c959be65bffa3b70ee80d6469a0775
Parents: c23bb29
Author: Benjamin Mahler <bm...@apache.org>
Authored: Thu Jul 19 14:41:00 2018 -0700
Committer: Benjamin Mahler <bm...@apache.org>
Committed: Tue Jul 24 18:33:24 2018 -0700

----------------------------------------------------------------------
 3rdparty/stout/tests/json_tests.cpp    | 21 ++++++++++++--
 3rdparty/stout/tests/jsonify_tests.cpp | 43 ++++++++++++++++++++++++-----
 2 files changed, 54 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/97420515/3rdparty/stout/tests/json_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/json_tests.cpp b/3rdparty/stout/tests/json_tests.cpp
index 508d843..ee44edf 100644
--- a/3rdparty/stout/tests/json_tests.cpp
+++ b/3rdparty/stout/tests/json_tests.cpp
@@ -37,15 +37,30 @@ TEST(JsonTest, DefaultValueIsNull)
 }
 
 
-TEST(JsonTest, BinaryData)
+TEST(JsonTest, UTF8)
 {
-  JSON::String s(string("\"\\/\b\f\n\r\t\x00\x19 !#[]\x7F\xFF", 17));
+  // We don't use the optional \uXXXX escaping for UTF-8,
+  // unless required (" U+0022, \ U+005C, and the control
+  // characters U+0000 to U+001F).
+  JSON::String s("Hello! \x01\x1F\x22\x5C \xF0\x9F\x98\x80");
 
-  EXPECT_EQ("\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007f\xFF\"",
+  EXPECT_EQ("\"Hello! \\u0001\\u001F\\\"\\\\ \xF0\x9F\x98\x80\"",
             stringify(s));
 }
 
 
+TEST(JsonTest, InvalidUTF8)
+{
+  // There currently is no validation either when constructing
+  // invalid UTF-8 string, or during serialization. Here, we
+  // use a 4 byte sequence but only provide the first byte.
+  // For now, this just gets passed through.
+  JSON::String s("\xF0");
+
+  EXPECT_EQ("\"\xF0\"", stringify(s));
+}
+
+
 TEST(JsonTest, NumberFormat)
 {
   // Test whole numbers (as doubles).

http://git-wip-us.apache.org/repos/asf/mesos/blob/97420515/3rdparty/stout/tests/jsonify_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/jsonify_tests.cpp b/3rdparty/stout/tests/jsonify_tests.cpp
index 7de95a4..39f6745 100644
--- a/3rdparty/stout/tests/jsonify_tests.cpp
+++ b/3rdparty/stout/tests/jsonify_tests.cpp
@@ -118,9 +118,19 @@ TEST(JsonifyTest, JSONNumberValue)
 TEST(JsonifyTest, String)
 {
   EXPECT_EQ("\"hello world!\"", string(jsonify("hello world!")));
+
+  // We don't use the optional \uXXXX escaping for UTF-8,
+  // unless required (" U+0022, \ U+005C, and the control
+  // characters U+0000 to U+001F).
   EXPECT_EQ(
-      "\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007f\xFF\"",
-      string(jsonify(string("\"\\/\b\f\n\r\t\x00\x19 !#[]\x7F\xFF", 17))));
+      "\"Hello! \\u0001\\u001F\\\"\\\\ \xF0\x9F\x98\x80\"",
+      string(jsonify("Hello! \x01\x1F\x22\x5C \xF0\x9F\x98\x80")));
+
+  // There currently is no validation either when constructing
+  // invalid UTF-8 string, or during serialization. Here, we
+  // use a 4 byte sequence but only provide the first byte.
+  // For now, this just gets passed through.
+  EXPECT_EQ("\"\xF0\"", string(jsonify("\xF0")));
 }
 
 
@@ -128,10 +138,20 @@ TEST(JsonifyTest, String)
 TEST(JsonifyTest, JSONString)
 {
   EXPECT_EQ("\"hello world!\"", string(jsonify(JSON::String("hello world!"))));
+
+  // We don't use the optional \uXXXX escaping for UTF-8,
+  // unless required (" U+0022, \ U+005C, and the control
+  // characters U+0000 to U+001F).
   EXPECT_EQ(
-      "\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007f\xFF\"",
+      "\"Hello! \\u0001\\u001F\\\"\\\\ \xF0\x9F\x98\x80\"",
       string(jsonify(
-          JSON::String(string("\"\\/\b\f\n\r\t\x00\x19 !#[]\x7F\xFF", 17)))));
+          JSON::String("Hello! \x01\x1F\x22\x5C \xF0\x9F\x98\x80"))));
+
+  // There currently is no validation either when constructing
+  // invalid UTF-8 string, or during serialization. Here, we
+  // use a 4 byte sequence but only provide the first byte.
+  // For now, this just gets passed through.
+  EXPECT_EQ("\"\xF0\"", string(jsonify(JSON::String("\xF0"))));
 }
 
 
@@ -140,10 +160,19 @@ TEST(JsonifyTest, JSONString)
 TEST(JsonifyTest, JSONStringValue)
 {
   EXPECT_EQ("\"hello world!\"", string(jsonify(JSON::Value("hello world!"))));
+
+  // We don't use the optional \uXXXX escaping for UTF-8,
+  // unless required (" U+0022, \ U+005C, and the control
+  // characters U+0000 to U+001F).
   EXPECT_EQ(
-      "\"\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0000\\u0019 !#[]\\u007f\xFF\"",
-      string(jsonify(
-          JSON::Value(string("\"\\/\b\f\n\r\t\x00\x19 !#[]\x7F\xFF", 17)))));
+      "\"Hello! \\u0001\\u001F\\\"\\\\ \xF0\x9F\x98\x80\"",
+      string(jsonify(JSON::Value("Hello! \x01\x1F\x22\x5C \xF0\x9F\x98\x80"))));
+
+  // There currently is no validation either when constructing
+  // invalid UTF-8 string, or during serialization. Here, we
+  // use a 4 byte sequence but only provide the first byte.
+  // For now, this just gets passed through.
+  EXPECT_EQ("\"\xF0\"", string(jsonify(JSON::Value("\xF0"))));
 }