Skip to content

Commit 19ac33b

Browse files
Support more chars in type URLs in the C++ text-format parser.
Change the C++ text-format parser to allow for more characters and formats in the type URL prefixes of expanded Any protos. This follows a recent change to the text-format spec which we are now closely following [1,2]. Note: This change modifies the default implementation of the `Finder` interface by removing [this special treatment](https://github.com/protocolbuffers/protobuf/blob/135bec4ee8c7cb8f9f8f2d5723bda5005948fa69/src/google/protobuf/text_format.cc#L255-L258) of non-standard type URLs. Any protos with type URL prefixes that are not `type.googleapis.com/` or `type.googleprod.com/` won't be treated specially anymore when converting to or from textproto using the default settings (for example, when using `TextFormat::PrintToString()` or `TextFormat::ParseFromString()`). In particular, Any protos with a non-standard type URL prefix will now get expanded by default when printed to textproto with the [`SetExpandAny()`](https://github.com/protocolbuffers/protobuf/blob/135bec4ee8c7cb8f9f8f2d5723bda5005948fa69/src/google/protobuf/text_format.h#L406) option enabled. Refs: - [1] https://protobuf.dev/reference/protobuf/textformat-spec/#characters - [2] https://protobuf.dev/reference/protobuf/textformat-spec/#field- PiperOrigin-RevId: 844790397
1 parent 135bec4 commit 19ac33b

File tree

7 files changed

+510
-322
lines changed

7 files changed

+510
-322
lines changed

src/google/protobuf/compiler/parser.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,10 @@ bool Parser::ParseOption(Message* options,
16661666
return false;
16671667
}
16681668
break;
1669+
1670+
case io::Tokenizer::TYPE_URL_CHARS:
1671+
ABSL_LOG(FATAL) << "Unexpected token type (URL chars).";
1672+
return false;
16691673
}
16701674
}
16711675

src/google/protobuf/io/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ cc_library(
140140
"@abseil-cpp//absl/log:absl_check",
141141
"@abseil-cpp//absl/log:absl_log",
142142
"@abseil-cpp//absl/strings",
143+
"@abseil-cpp//absl/strings:charset",
143144
"@abseil-cpp//absl/strings:str_format",
144145
],
145146
)

0 commit comments

Comments
 (0)