From d1f7715dda69b61347447b9ee3399e11e8349dfa Mon Sep 17 00:00:00 2001 From: Geoffrey Gilmore Date: Wed, 29 May 2024 02:18:42 -0700 Subject: [PATCH] gitserver: grpc: relax BlameAuthor name field to allow arbitrary byte sequences (#62917) --- internal/gitserver/gitdomain/common.go | 4 ++-- internal/gitserver/v1/gitserver.pb.go | 8 ++++---- internal/gitserver/v1/gitserver.proto | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/gitserver/gitdomain/common.go b/internal/gitserver/gitdomain/common.go index 2dfd7da97e1..6a7241e806a 100644 --- a/internal/gitserver/gitdomain/common.go +++ b/internal/gitserver/gitdomain/common.go @@ -278,7 +278,7 @@ func HunkFromBlameProto(h *proto.BlameHunk) *Hunk { Message: h.GetMessage(), Filename: h.GetFilename(), Author: Signature{ - Name: h.GetAuthor().GetName(), + Name: string(h.GetAuthor().GetName()), // Note: This is not necessarily a valid UTF-8 string, as git does not enforce this. Email: h.GetAuthor().GetEmail(), Date: h.GetAuthor().GetDate().AsTime(), }, @@ -307,7 +307,7 @@ func (h *Hunk) ToProto() *proto.BlameHunk { Message: h.Message, Filename: h.Filename, Author: &proto.BlameAuthor{ - Name: h.Author.Name, + Name: []byte(h.Author.Name), // We can't guarantee this is valid UTF-8. So, we have to use []byte. Email: h.Author.Email, Date: timestamppb.New(h.Author.Date), }, diff --git a/internal/gitserver/v1/gitserver.pb.go b/internal/gitserver/v1/gitserver.pb.go index 1b0fb8a72da..c7bda28b342 100644 --- a/internal/gitserver/v1/gitserver.pb.go +++ b/internal/gitserver/v1/gitserver.pb.go @@ -2741,7 +2741,7 @@ type BlameAuthor struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Name []byte `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Email string `protobuf:"bytes,2,opt,name=email,proto3" json:"email,omitempty"` Date *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=date,proto3" json:"date,omitempty"` } @@ -2778,11 +2778,11 @@ func (*BlameAuthor) Descriptor() ([]byte, []int) { return file_gitserver_proto_rawDescGZIP(), []int{34} } -func (x *BlameAuthor) GetName() string { +func (x *BlameAuthor) GetName() []byte { if x != nil { return x.Name } - return "" + return nil } func (x *BlameAuthor) GetEmail() string { @@ -8020,7 +8020,7 @@ var file_gitserver_proto_rawDesc = []byte{ 0x69, 0x6f, 0x75, 0x73, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x88, 0x01, 0x01, 0x42, 0x12, 0x0a, 0x10, 0x5f, 0x70, 0x72, 0x65, 0x76, 0x69, 0x6f, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x22, 0x67, 0x0a, 0x0b, 0x42, 0x6c, 0x61, 0x6d, 0x65, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, - 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x6d, 0x61, 0x69, 0x6c, 0x12, 0x2e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, diff --git a/internal/gitserver/v1/gitserver.proto b/internal/gitserver/v1/gitserver.proto index 07de31b0466..c0e4b56b862 100644 --- a/internal/gitserver/v1/gitserver.proto +++ b/internal/gitserver/v1/gitserver.proto @@ -679,7 +679,7 @@ message BlameHunk { } message BlameAuthor { - string name = 1; + bytes name = 1; string email = 2; google.protobuf.Timestamp date = 3; }