Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatter issue with message literals with any syntax #2650

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}