Skip to content

Commit

Permalink
Fix formatter issue with message literals with any syntax (#2650)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump authored Dec 8, 2023
1 parent 44af737 commit b06ab38
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
`use_enum_numbers`. This affects output serialization. Some examples:
- `buf convert --type foo.Bar --from input.binpb --to output.yaml#use_proto_names=true`
- `buf convert --type foo.Bar --from input.binpb --to -#format=yaml,use_enum_numbers=true`
- Fix issue where `buf format` would inadvertently mangle files that used
the [expanded `Any` syntax](https://protobuf.com/docs/language-spec#any-messages)
in option values.

## [v1.28.1] - 2023-11-15

Expand Down
4 changes: 4 additions & 0 deletions private/buf/bufformat/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,10 @@ func (f *formatter) writeMessageFieldPrefix(messageFieldNode *ast.MessageFieldNo
fieldReferenceNode := messageFieldNode.Name
if fieldReferenceNode.Open != nil {
f.writeStart(fieldReferenceNode.Open)
if fieldReferenceNode.URLPrefix != nil {
f.writeInline(fieldReferenceNode.URLPrefix)
f.writeInline(fieldReferenceNode.Slash)
}
f.writeInline(fieldReferenceNode.Name)
} else {
f.writeStart(fieldReferenceNode.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto2";

package foo.bar;

import "google/protobuf/any.proto";
import "google/protobuf/descriptor.proto";

message Simple {
Expand All @@ -26,6 +27,17 @@ message Test {

extensions 249, 300 to 350, 500 to 550, 20000 to max [(label) = "jazz"];

option (any) = {
[type.googleapis.com/foo.bar.Test]: {
foo: "abc"
array: [
1,
2,
3
]
}
};

message Nested {
extend google.protobuf.MessageOptions {
optional int32 fooblez = 20003;
Expand Down Expand Up @@ -70,4 +82,5 @@ message Test {
extend google.protobuf.MessageOptions {
repeated Test rept = 20002;
optional Test.Nested._NestedNested.EEE eee = 20010;
optional google.protobuf.Any any = 20300;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto2";

package foo.bar;

import "google/protobuf/any.proto";
import "google/protobuf/descriptor.proto";

message Simple {
Expand All @@ -28,6 +29,12 @@ message Test {

extensions 249, 300 to 350, 500 to 550, 20000 to max [(label) = "jazz"];

option (any) = {
[ type . googleapis . com/ foo.bar.Test ]: {
foo: "abc" array: [1,2,3]
}
};

message Nested {
extend google.protobuf.MessageOptions {
optional int32 fooblez = 20003;
Expand Down Expand Up @@ -69,4 +76,5 @@ message Test {
extend google.protobuf.MessageOptions {
repeated Test rept = 20002;
optional Test.Nested._NestedNested.EEE eee = 20010;
optional google.protobuf.Any any = 20300;
}

0 comments on commit b06ab38

Please sign in to comment.