Automated rollback of commit b55b834d5a.

PiperOrigin-RevId: 534168300
pull/12875/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent d5d7654efe
commit a6d895988d
  1. 4
      objectivec/GPBAny.pbobjc.m
  2. 12
      objectivec/GPBApi.pbobjc.m
  3. 4
      objectivec/GPBDuration.pbobjc.m
  4. 4
      objectivec/GPBEmpty.pbobjc.m
  5. 4
      objectivec/GPBFieldMask.pbobjc.m
  6. 4
      objectivec/GPBSourceContext.pbobjc.m
  7. 12
      objectivec/GPBStruct.pbobjc.m
  8. 4
      objectivec/GPBTimestamp.pbobjc.m
  9. 20
      objectivec/GPBType.pbobjc.m
  10. 36
      objectivec/GPBWrappers.pbobjc.m
  11. 1
      src/google/protobuf/lite_unittest.cc
  12. 12
      src/google/protobuf/message.h
  13. 8
      src/google/protobuf/message_lite.cc
  14. 4
      src/google/protobuf/message_lite.h
  15. 47
      src/google/protobuf/text_format.cc
  16. 14
      src/google/protobuf/text_format.h
  17. 100
      src/google/protobuf/text_format_unittest.cc
  18. 16
      src/google/protobuf/unittest.proto

@ -91,9 +91,9 @@ typedef struct GPBAny__storage_ {
"\001\001\004\241!!\000";
[localDescriptor setupExtraTextInfo:extraTextFormatInfo];
#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -145,9 +145,9 @@ typedef struct GPBApi__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBApi__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -272,9 +272,9 @@ typedef struct GPBMethod__storage_ {
"\002\002\007\244\241!!\000\004\010\244\241!!\000";
[localDescriptor setupExtraTextInfo:extraTextFormatInfo];
#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -341,9 +341,9 @@ typedef struct GPBMixin__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBMixin__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -86,9 +86,9 @@ typedef struct GPBDuration__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBDuration__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -62,9 +62,9 @@ typedef struct GPBEmpty__storage_ {
fieldCount:0
storageSize:sizeof(GPBEmpty__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -75,9 +75,9 @@ typedef struct GPBFieldMask__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBFieldMask__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -75,9 +75,9 @@ typedef struct GPBSourceContext__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBSourceContext__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -115,9 +115,9 @@ typedef struct GPBStruct__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBStruct__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -222,9 +222,9 @@ typedef struct GPBValue__storage_ {
[localDescriptor setupOneofs:oneofs
count:(uint32_t)(sizeof(oneofs) / sizeof(char*))
firstHasIndex:-1];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -285,9 +285,9 @@ typedef struct GPBListValue__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBListValue__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -86,9 +86,9 @@ typedef struct GPBTimestamp__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBTimestamp__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -307,9 +307,9 @@ typedef struct GPBType__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBType__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -468,9 +468,9 @@ typedef struct GPBField__storage_ {
"\001\006\004\241!!\000";
[localDescriptor setupExtraTextInfo:extraTextFormatInfo];
#endif // !GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -593,9 +593,9 @@ typedef struct GPBEnum__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBEnum__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -673,9 +673,9 @@ typedef struct GPBEnumValue__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBEnumValue__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -730,9 +730,9 @@ typedef struct GPBOption__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBOption__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -83,9 +83,9 @@ typedef struct GPBDoubleValue__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBDoubleValue__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -129,9 +129,9 @@ typedef struct GPBFloatValue__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBFloatValue__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -175,9 +175,9 @@ typedef struct GPBInt64Value__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBInt64Value__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -221,9 +221,9 @@ typedef struct GPBUInt64Value__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBUInt64Value__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -267,9 +267,9 @@ typedef struct GPBInt32Value__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBInt32Value__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -313,9 +313,9 @@ typedef struct GPBUInt32Value__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBUInt32Value__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -358,9 +358,9 @@ typedef struct GPBBoolValue__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBBoolValue__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -404,9 +404,9 @@ typedef struct GPBStringValue__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBStringValue__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;
@ -450,9 +450,9 @@ typedef struct GPBBytesValue__storage_ {
fieldCount:(uint32_t)(sizeof(fields) / sizeof(GPBMessageFieldDescription))
storageSize:sizeof(GPBBytesValue__storage_)
flags:(GPBDescriptorInitializationFlags)(GPBDescriptorInitializationFlag_UsesClassRefs | GPBDescriptorInitializationFlag_Proto3OptionalKnown | GPBDescriptorInitializationFlag_ClosedEnumSupportKnown)];
#if defined(DEBUG) && DEBUG
#if defined(DEBUG) && DEBUG
NSAssert(descriptor == nil, @"Startup recursed!");
#endif // DEBUG
#endif // DEBUG
descriptor = localDescriptor;
}
return descriptor;

@ -36,6 +36,7 @@
#include <string>
#include <utility>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "absl/log/absl_check.h"
#include "absl/strings/match.h"

@ -182,10 +182,13 @@ class CelMapReflectionFriend; // field_backed_map_impl.cc
namespace internal {
class MapFieldPrinterHelper; // text_format.cc
PROTOBUF_EXPORT void PerformAbslStringify(
const Message& message,
absl::FunctionRef<void(absl::string_view)> append); // text_format.cc
PROTOBUF_EXPORT std::string StringifyMessage(
const Message& message); // text_format.cc
} // namespace internal
PROTOBUF_EXPORT std::string ShortFormat(
const Message& message); // text_format.cc
PROTOBUF_EXPORT std::string Utf8Format(
const Message& message); // text_format.cc
namespace util {
class MessageDifferencer;
}
@ -340,8 +343,7 @@ class PROTOBUF_EXPORT Message : public MessageLite {
// Do not rely on exact format.
template <typename Sink>
friend void AbslStringify(Sink& sink, const google::protobuf::Message& message) {
internal::PerformAbslStringify(
message, [&](absl::string_view content) { sink.Append(content); });
sink.Append(internal::StringifyMessage(message));
}
// Reflection-based methods ----------------------------------------

@ -657,6 +657,14 @@ void InternalMetadata::DoSwap<std::string>(std::string* other) {
} // namespace internal
std::string ShortFormat(const MessageLite& message_lite) {
return message_lite.DebugString();
}
std::string Utf8Format(const MessageLite& message_lite) {
return message_lite.DebugString();
}
// ===================================================================
// Shutdown support.

@ -617,6 +617,10 @@ T* OnShutdownDelete(T* p) {
}
} // namespace internal
std::string ShortFormat(const MessageLite& message_lite);
std::string Utf8Format(const MessageLite& message_lite);
} // namespace protobuf
} // namespace google

@ -99,6 +99,13 @@ inline void IncrementRedactedFieldCounter() {
num_redacted_field.fetch_add(1, std::memory_order_relaxed);
}
inline void TrimTrailingSpace(std::string& debug_string) {
// Single line mode currently might have an extra space at the end.
if (!debug_string.empty() && debug_string.back() == ' ') {
debug_string.pop_back();
}
}
} // namespace
namespace internal {
@ -140,10 +147,7 @@ std::string Message::ShortDebugString() const {
std::memory_order_relaxed));
printer.PrintToString(*this, &debug_string);
// Single line mode currently might have an extra space at the end.
if (!debug_string.empty() && debug_string[debug_string.size() - 1] == ' ') {
debug_string.resize(debug_string.size() - 1);
}
TrimTrailingSpace(debug_string);
return debug_string;
}
@ -168,24 +172,51 @@ void Message::PrintDebugString() const { printf("%s", DebugString().c_str()); }
namespace internal {
PROTOBUF_EXPORT void PerformAbslStringify(
const Message& message, absl::FunctionRef<void(absl::string_view)> append) {
enum class Option { kNone, kShort, kUTF8 };
std::string StringifyMessage(const Message& message, Option option) {
// Indicate all scoped reflection calls are from DebugString function.
ScopedReflectionMode scope(ReflectionMode::kDebugString);
// TODO(b/249835002): consider using the single line version for short
TextFormat::Printer printer;
switch (option) {
case Option::kShort:
printer.SetSingleLineMode(true);
break;
case Option::kUTF8:
printer.SetUseUtf8StringEscaping(true);
break;
case Option::kNone:
break;
}
printer.SetExpandAny(true);
printer.SetRedactDebugString(true);
printer.SetRandomizeDebugString(true);
printer.SetRootMessageFullName(message.GetDescriptor()->full_name());
std::string result;
printer.PrintToString(message, &result);
append(result);
if (option == Option::kShort) {
TrimTrailingSpace(result);
}
return result;
}
PROTOBUF_EXPORT std::string StringifyMessage(const Message& message) {
return StringifyMessage(message, Option::kNone);
}
} // namespace internal
PROTOBUF_EXPORT std::string ShortFormat(const Message& message) {
return internal::StringifyMessage(message, internal::Option::kShort);
}
PROTOBUF_EXPORT std::string Utf8Format(const Message& message) {
return internal::StringifyMessage(message, internal::Option::kUTF8);
}
// ===========================================================================
// Implementation of the parse information tree class.

@ -76,6 +76,15 @@ namespace io {
class ErrorCollector; // tokenizer.h
}
namespace internal {
// Enum used to set printing options for StringifyMessage.
PROTOBUF_EXPORT enum class Option;
// Converts a protobuf message to a string with redaction enabled.
PROTOBUF_EXPORT std::string StringifyMessage(const Message& message,
Option option);
} // namespace internal
// This class implements protocol buffer text format, colloquially known as text
// proto. Printing and parsing protocol messages in text format is useful for
// debugging and human editing of messages.
@ -421,9 +430,8 @@ class PROTOBUF_EXPORT TextFormat {
friend std::string Message::DebugString() const;
friend std::string Message::ShortDebugString() const;
friend std::string Message::Utf8DebugString() const;
friend void internal::PerformAbslStringify(
const Message& message,
absl::FunctionRef<void(absl::string_view)> append);
friend std::string internal::StringifyMessage(const Message& message,
internal::Option option);
// Sets whether silent markers will be inserted.
void SetInsertSilentMarker(bool v) { insert_silent_marker_ = v; }

@ -60,6 +60,7 @@
#include "google/protobuf/io/tokenizer.h"
#include "google/protobuf/io/zero_copy_stream_impl.h"
#include "google/protobuf/map_unittest.pb.h"
#include "google/protobuf/message.h"
#include "google/protobuf/test_util.h"
#include "google/protobuf/test_util2.h"
#include "google/protobuf/unittest.pb.h"
@ -163,6 +164,105 @@ TEST_F(TextFormatTest, ShortDebugString) {
}
TEST_F(TextFormatTest, ShortFormat) {
unittest::RedactedFields proto;
unittest::TestNestedMessageRedaction redacted_nested_proto;
unittest::TestNestedMessageRedaction unredacted_nested_proto;
redacted_nested_proto.set_optional_nested_string("hello");
unredacted_nested_proto.set_optional_nested_string("world");
proto.set_optional_redacted_string("foo");
proto.set_optional_unredacted_string("bar");
proto.add_repeated_redacted_string("1");
proto.add_repeated_redacted_string("2");
proto.add_repeated_unredacted_string("3");
proto.add_repeated_unredacted_string("4");
*proto.mutable_optional_redacted_message() = redacted_nested_proto;
*proto.mutable_optional_unredacted_message() = unredacted_nested_proto;
unittest::TestNestedMessageRedaction* redacted_message_1 =
proto.add_repeated_redacted_message();
unittest::TestNestedMessageRedaction* redacted_message_2 =
proto.add_repeated_redacted_message();
unittest::TestNestedMessageRedaction* unredacted_message_1 =
proto.add_repeated_unredacted_message();
unittest::TestNestedMessageRedaction* unredacted_message_2 =
proto.add_repeated_unredacted_message();
redacted_message_1->set_optional_nested_string("5");
redacted_message_2->set_optional_nested_string("6");
unredacted_message_1->set_optional_nested_string("7");
unredacted_message_2->set_optional_nested_string("8");
(*proto.mutable_map_redacted_string())["abc"] = "def";
(*proto.mutable_map_unredacted_string())["ghi"] = "jkl";
EXPECT_THAT(
google::protobuf::ShortFormat(proto),
testing::MatchesRegex(
"optional_redacted_string: \\[REDACTED\\] "
"optional_unredacted_string: \"bar\" "
"repeated_redacted_string: \\[REDACTED\\] "
"repeated_redacted_string: \\[REDACTED\\] "
"repeated_unredacted_string: \"3\" "
"repeated_unredacted_string: \"4\" "
"optional_redacted_message: \\[REDACTED\\] "
"optional_unredacted_message \\{ "
"optional_nested_string: \"world\" \\} "
"repeated_redacted_message: \\[REDACTED\\] "
"repeated_unredacted_message \\{ optional_nested_string: \"7\" \\} "
"repeated_unredacted_message \\{ optional_nested_string: \"8\" \\} "
"map_redacted_string: \\[REDACTED\\] "
"map_unredacted_string \\{ key: \"ghi\" value: \"jkl\" \\}"));
}
TEST_F(TextFormatTest, Utf8Format) {
unittest::RedactedFields proto;
unittest::TestNestedMessageRedaction redacted_nested_proto;
unittest::TestNestedMessageRedaction unredacted_nested_proto;
redacted_nested_proto.set_optional_nested_string("\350\260\267\346\255\214");
unredacted_nested_proto.set_optional_nested_string(
"\350\260\267\346\255\214");
proto.set_optional_redacted_string("foo");
proto.set_optional_unredacted_string("bar");
proto.add_repeated_redacted_string("1");
proto.add_repeated_redacted_string("2");
proto.add_repeated_unredacted_string("3");
proto.add_repeated_unredacted_string("4");
*proto.mutable_optional_redacted_message() = redacted_nested_proto;
*proto.mutable_optional_unredacted_message() = unredacted_nested_proto;
unittest::TestNestedMessageRedaction* redacted_message_1 =
proto.add_repeated_redacted_message();
unittest::TestNestedMessageRedaction* redacted_message_2 =
proto.add_repeated_redacted_message();
unittest::TestNestedMessageRedaction* unredacted_message_1 =
proto.add_repeated_unredacted_message();
unittest::TestNestedMessageRedaction* unredacted_message_2 =
proto.add_repeated_unredacted_message();
redacted_message_1->set_optional_nested_string("5");
redacted_message_2->set_optional_nested_string("6");
unredacted_message_1->set_optional_nested_string("7");
unredacted_message_2->set_optional_nested_string("8");
(*proto.mutable_map_redacted_string())["abc"] = "def";
(*proto.mutable_map_unredacted_string())["ghi"] = "jkl";
EXPECT_THAT(google::protobuf::Utf8Format(proto),
testing::MatchesRegex(
"optional_redacted_string: \\[REDACTED\\]\n"
"optional_unredacted_string: \"bar\"\n"
"repeated_redacted_string: \\[REDACTED\\]\n"
"repeated_redacted_string: \\[REDACTED\\]\n"
"repeated_unredacted_string: \"3\"\n"
"repeated_unredacted_string: \"4\"\n"
"optional_redacted_message: \\[REDACTED\\]\n"
"optional_unredacted_message \\{\n "
"optional_nested_string: \"\xE8\xB0\xB7\xE6\xAD\x8C\"\n\\}\n"
"repeated_redacted_message: \\[REDACTED\\]\n"
"repeated_unredacted_message \\{\n "
"optional_nested_string: \"7\"\n\\}\n"
"repeated_unredacted_message \\{\n "
"optional_nested_string: \"8\"\n\\}\n"
"map_redacted_string: \\[REDACTED\\]\n"
"map_unredacted_string \\{\n "
"key: \"ghi\"\n value: \"jkl\"\n\\}\n"));
}
TEST_F(TextFormatTest, ShortPrimitiveRepeateds) {
proto_.set_optional_int32(123);
proto_.add_repeated_int32(456);

@ -1663,8 +1663,22 @@ message BadFieldNames{
optional int32 for = 2;
}
message RedactedFields{
message TestNestedMessageRedaction {
optional string optional_nested_string = 1;
}
message RedactedFields {
optional string optional_redacted_string = 1 [debug_redact = true];
optional string optional_unredacted_string = 2;
repeated string repeated_redacted_string = 3 [debug_redact = true];
repeated string repeated_unredacted_string = 4;
optional TestNestedMessageRedaction optional_redacted_message = 5 [debug_redact = true];
optional TestNestedMessageRedaction optional_unredacted_message = 6;
repeated TestNestedMessageRedaction repeated_redacted_message = 7
[debug_redact = true];
repeated TestNestedMessageRedaction repeated_unredacted_message = 8;
map<string, string> map_redacted_string = 9 [debug_redact = true];
map<string, string> map_unredacted_string = 10;
}
message TestCord{

Loading…
Cancel
Save