Protobuf: C++ JSON parser incorrectly accepts lowercase enum value names.

Created on 17 Aug 2018  路  2Comments  路  Source: protocolbuffers/protobuf

Given this proto definition:

enum Category {
    NOT_SPECIFIED = 0;
    LISTINGS = 1;
    REPUTATION = 2;
}

The C++ JSON parser should only accept "LISTINGS" as enum field values, but right now it accepts "listings" (converted to lower-case) as well.

For enum fields, proto3 JSON spec says "The name of the enum value as specified in proto is used":
https://developers.google.com/protocol-buffers/docs/proto3#json

"as specified in proto" should be interpreted as "the exactly same name including casing as specified in proto".

bug c++ json

Most helpful comment

Well, that only works if the enum name is defined all upper case. If the enum is defined as:

enum Category {
    NotSpecified = 0;
    Listings = 1;
    Reputation = 2;
}

Neither "listings" nor "LISTINGS" will be accepted... With the above definition, only "Listings" works.

All 2 comments

Apparently C++ JSON parser not only accepts lower-case enum value names, but actually accepts arbitrary casing like "Listings" or "LiStInGs"...

Well, that only works if the enum name is defined all upper case. If the enum is defined as:

enum Category {
    NotSpecified = 0;
    Listings = 1;
    Reputation = 2;
}

Neither "listings" nor "LISTINGS" will be accepted... With the above definition, only "Listings" works.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mitar picture mitar  路  37Comments

blowmage picture blowmage  路  73Comments

mkosieradzki picture mkosieradzki  路  70Comments

xfxyjwf picture xfxyjwf  路  35Comments

liujisi picture liujisi  路  48Comments