Explorar o código

internal/proto: set filename in FileDescriptorProto when missing

Some old descriptors don't include a filename. When missing, set it from
the filename provided to proto.RegisterFile.

Fixes a number of warnings in the google.golang.org/protobuf tests
stemming from the legacy generated files:

	WARNING: proto: file "" is already registered
	A future release of proto will panic on registration conflicts.

Change-Id: I4f7c9e4a9ecb4d2a71073b0a373ec0c800e2ec66
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/184078
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Damien Neil %!s(int64=6) %!d(string=hai) anos
pai
achega
346ae1c1ba
Modificáronse 1 ficheiros con 4 adicións e 0 borrados
  1. 4 0
      internal/proto/registry.go

+ 4 - 0
internal/proto/registry.go

@@ -52,6 +52,10 @@ func RegisterFile(s filePath, d fileDescGZIP) {
 	if err := protoV2.Unmarshal(b, &pb); err != nil {
 		panic(fmt.Sprintf("proto: unmarshal failure: %v", err))
 	}
+	// Some old descriptors don't include the filename.
+	if pb.Name == nil {
+		pb.Name = &s
+	}
 
 	// Convert the raw descriptor to a structured file descriptor.
 	fd, err := protodesc.NewFile(&pb, nil)