Repository navigation
any: read a type URL without a '/' as a bare message name - #692
Merged
Merged
Conversation
A `google.protobuf.Any` whose `type_url` has no `/` was resolved by
`DynamicMessage` and rejected by the generated `Any` JSON parser.
`any.proto` requires the `/`; protobuf-go and Python read a bare full
name anyway, and C++ and Java reject it.
Both JSON parsers now accept a bare name that resolves. The generated
parser reads `{"@type": "pkg.Message", ...}` when the type registry has
a JSON entry for `pkg.Message`, and the serializer writes such an `Any`
expanded. A bare name that does not resolve stays a parse error and is
never read in the base64 form, which the conformance test
`AnyWktRepresentationWithBadType` requires. `Any::type_name`,
`is_message` and `unpack_message` read a URL without a `/` as the name,
and `AnyRegistry::lookup` matches one by name.
`JsonParseOptions::strict_any_type_urls` and
`DynamicMessageSeed::strict_any_type_urls` reject an `@type` without a
`/` when parsing. The reflective seeds carry the two parse options in
one `ParseFlags` value.
Text format does not resolve a bare name, because `[pkg.Message] { }`
is the syntax of an extension field.
|
All contributors have signed the CLA ✍️ ✅ |
iainmcgin
marked this pull request as ready for review
October 10, 2026 18:25
iainmcgin
enabled auto-merge
October 10, 2026 18:26
rpb-ant
approved these changes
Oct 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A
google.protobuf.Anywhosetype_urlhas no/was resolved byDynamicMessageand rejected by the generatedAnyJSON parser.any.protorequires the/; protobuf-go and Python read a bare full name anyway, and C++ and Java reject it.AnyJSON parser accepts{"@type": "pkg.Message", ...}when the type registry has a JSON entry forpkg.Message. Such anAnyis now written expanded; it was written as base64 undervalue, which the same parser rejected. A payload that does not decode as that message now fails to serialize.AnyWktRepresentationWithBadTyperequires that. The serializer still writes the base64 form for such anAny, so it does not round-trip.AnyRegistry::lookupandTypeRegistry::json_any_by_urlfind an entry by a bare name, and an entry registered under a bare name is found under any URL prefix.Any::type_name,is_messageandunpack_message(unreleased, any: add typed pack and unpack helpers #499) read a URL without a/as the name.JsonParseOptions::strict_any_type_urlsandDynamicMessageSeed::strict_any_type_urlsreject an@typewithout a/, at any depth ofAnyinAny. The reflective seeds pass both parse options down in oneParseFlagsvalue, which is most of the change inreflect/json.rs.Serialization,
DynamicMessage::unpack_anyandAny::type_nametake no options and resolve a bare name. Text format does not resolve a bare name, because[pkg.Message] { ... }is the syntax of an extension field.The error for an empty
@type, or one ending in/, now reads@type "..." is not a valid type URL: it names no type.The changelog entry is
Changed. #485, which changed the same output for a URL with an unregistered prefix, is filed underBreaking changes; 0.9.2 could not parse a bare@typeat all, so less depends on the old output here.Supersedes #524, which made the reflective path reject a bare name.