Skip to content

FieldMask shouldn't convert names with trailing underscore #1321

Description

@AdrienVannson

When converting a field mask to JSON, path values with a trailing underscore are converted instead of being rejected.

import { create, toJson, fromJson } from "@bufbuild/protobuf";
import { FieldMaskSchema } from "@bufbuild/protobuf/wkt";

var msg = create(FieldMaskSchema, { paths: ["abc_"] });
console.log(msg);

var json = toJson(FieldMaskSchema, msg);  // Should fail but works
console.log(json);

var msg2 = fromJson(FieldMaskSchema, json);  // The underscore is lost
console.log(msg2);

In the same situation, the official Python implementation fails:

from google.protobuf.field_mask_pb2 import FieldMask
from google.protobuf.json_format import MessageToJson

msg = FieldMask(paths=["abc_"])
MessageToJson(msg)  # ValueError: Fail to print FieldMask to Json string: Trailing "_" in path name abc_.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions