Skip to content

Commit

Permalink
fix: Add / prefix to Any TypeURL (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaury1093 authored Dec 1, 2022
1 parent ad42ce8 commit 2a5156b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion any/any.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func MarshalFrom(dst *anypb.Any, src proto.Message, opts proto.MarshalOptions) e
if err != nil {
return err
}
dst.TypeUrl = string(src.ProtoReflect().Descriptor().FullName())
dst.TypeUrl = "/" + string(src.ProtoReflect().Descriptor().FullName())
dst.Value = b
return nil
}
4 changes: 2 additions & 2 deletions any/any_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ func TestAny(t *testing.T) {
dst1 := &anypb.Any{}
err := any.MarshalFrom(dst1, value, proto.MarshalOptions{})
require.NoError(t, err)
require.Equal(t, "A", dst1.TypeUrl) // Make sure there's no "type.googleapis.com/" prefix.
require.Equal(t, "/A", dst1.TypeUrl) // Make sure there's no "type.googleapis.com/" prefix.

dst2, err := any.New(value)
require.NoError(t, err)
require.Equal(t, "A", dst2.TypeUrl) // Make sure there's no "type.googleapis.com/" prefix.
require.Equal(t, "/A", dst2.TypeUrl) // Make sure there's no "type.googleapis.com/" prefix.

// Round trip.
newValue, err := anypb.UnmarshalNew(dst2, proto.UnmarshalOptions{})
Expand Down

0 comments on commit 2a5156b

Please sign in to comment.