Github user hcorg commented on a diff in the pull request:

    https://github.com/apache/thrift/pull/648#discussion_r42143016
  
    --- Diff: lib/cpp/test/JSONProtoTest.cpp ---
    @@ -269,3 +271,70 @@ BOOST_AUTO_TEST_CASE(test_json_proto_8) {
       BOOST_CHECK_THROW(ooe2.read(proto.get()),
         apache::thrift::protocol::TProtocolException);
     }
    +
    +std::string toHexSequence(const std::string& str) {
    +  std::stringstream ss;
    +  ss << std::hex << std::setfill('0');
    +  for (std::size_t i = 0; i < str.size(); i++) {
    +    ss << "\\x" << int(uint8_t(str[i]));
    +  }
    +  return ss.str();
    +}
    +
    +BOOST_AUTO_TEST_CASE(test_json_unicode_escaped) {
    +  const char* json_string =
    +  
"{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
    +  "\"5\":{\"i32\":16},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
    +  "53589793},\"8\":{\"str\":\"JSON THIS!\"},\"9\":{\"str\":\"\\u0e01 
\\ud835\\udd3e\"},"
    +  "\"10\":{\"tf\":0},\"11\":{\"str\":\"000000\"},\"12\":{\"lst\""
    +  
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
    +  "\",3,1,2,3]}}";
    +  const char* expected_zomg_unicode = "\xe0\xb8\x81 \xf0\x9d\x94\xbe";
    +
    +  boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
    +    (uint8_t*)(json_string), strlen(json_string)*sizeof(char)));
    +  boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
    +
    +  OneOfEach ooe2;
    +  ooe2.read(proto.get());
    +  BOOST_CHECK_MESSAGE(!ooe2.zomg_unicode.compare(expected_zomg_unicode),
    +    "Expected:\n" << toHexSequence(expected_zomg_unicode) << "\nGotten:\n"
    +                  << toHexSequence(ooe2.zomg_unicode));
    +
    +}
    +
    +BOOST_AUTO_TEST_CASE(test_json_unicode_escaped_missing_low_surrogate) {
    +  const char* json_string =
    +  
"{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
    +  "\"5\":{\"i32\":16},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
    +  "53589793},\"8\":{\"str\":\"JSON THIS!\"},\"9\":{\"str\":\"\\ud835\"},"
    +  "\"10\":{\"tf\":0},\"11\":{\"str\":\"000000\"},\"12\":{\"lst\""
    +  
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
    +  "\",3,1,2,3]}}";
    +
    +  boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
    +    (uint8_t*)(json_string), strlen(json_string)*sizeof(char)));
    +  boost::shared_ptr<TJSONProtocol> proto(new TJSONProtocol(buffer));
    +
    +  OneOfEach ooe2;
    +  BOOST_CHECK_THROW(ooe2.read(proto.get()),
    +    apache::thrift::protocol::TProtocolException);
    +}
    +
    +BOOST_AUTO_TEST_CASE(test_json_unicode_escaped_missing_hi_surrogate) {
    +  const char* json_string =
    +  
"{\"1\":{\"tf\":1},\"2\":{\"tf\":0},\"3\":{\"i8\":127},\"4\":{\"i16\":27000},"
    +  "\"5\":{\"i32\":16},\"6\":{\"i64\":6000000000},\"7\":{\"dbl\":3.1415926"
    +  "53589793},\"8\":{\"str\":\"JSON THIS!\"},\"9\":{\"str\":\"\\udd3e\"},"
    +  "\"10\":{\"tf\":0},\"11\":{\"str\":\"000000\"},\"12\":{\"lst\""
    +  
":[\"i8\",3,1,2,3]},\"13\":{\"lst\":[\"i16\",3,1,2,3]},\"14\":{\"lst\":[\"i64"
    +  "\",3,1,2,3]}}";
    +
    +  boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer(
    +    (uint8_t*)(json_string), strlen(json_string)*sizeof(char)));
    --- End diff --
    
    sizeof(char)  is by definition always equal 1 :) you could declare 
json_string as "const char json_string[]" and use "sizeof(json_string)"


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to