Skip to content

JsonFormat.printer does not correctly escape quotes in FieldMask proto #24083

@DylanRussell

Description

@DylanRussell

What version of protobuf and what language are you using?

Version: main
Language: Java

What operating system (Linux, Windows, ...) and version?

Linux

What did you do?

I have a proto like this:

message AuditFields {
   .google.protobuf.FieldMask field_mask = 1;
   repeated .google.protobuf.FieldMask field_mask_r = 2;
   repeated string string_r = 3;
}

Now I have this Java code:

    AuditFields.Builder fields =
        AuditFields.newBuilder()
            .setFieldMask(FieldMask.newBuilder().addPaths("\"").build())
            .addStringR("\"")
            .addFieldMaskR(FieldMask.newBuilder().addPaths("\"").build());
   System.out.println("fields: " + JsonFormat.printer().print(fields));

Which prints:

fields: {
  "stringR": ["\""],
  "fieldMask": """,
  "fieldMaskR": ["""]
} 

The quote is properly escaped in the repeated string field but NOT properly escaped in the repeated Field mask.

I think the bug has something to do with FieldMask having a special encoding: https://protobuf.dev/reference/protobuf/google.protobuf/#json-encoding-field-masks

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions