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

protoc: reserved names are not validated #6335

Closed
dsnet opened this issue Jul 3, 2019 · 11 comments · Fixed by #10586
Closed

protoc: reserved names are not validated #6335

dsnet opened this issue Jul 3, 2019 · 11 comments · Fixed by #10586
Assignees
Labels
bug inactive Denotes the issue/PR has not seen activity in the last 90 days. protoc

Comments

@dsnet
Copy link
Contributor

dsnet commented Jul 3, 2019

Consider the following proto file:

message M {
    optional string foo = 1; 
    reserved "foo bar";
}

Here, "foo bar" is clearly an invalid identifier. The intention of the user is to specify two different identifiers "foo" and "bar" as reserved. Since the reserved name logic looks for exact matches, it does not warn the user that a reserved name is being used.

I expect protoc to fail if any reserved identifier is invalid.

@dsnet
Copy link
Contributor Author

dsnet commented Jul 3, 2019

Related problem:

message M {
    optional string foo = 1; 
    reserved "foo" "bar";
}

Again, the intention is to specify "foo" and "bar" as two separate identifiers. However, since protoc seems to be applying a textproto-like grammar, "foo" "bar" is treated as a single concatenated string "foobar".

The distinction between:

  • reserved "foo bar";
  • reserved "foo" "bar";
  • reserved "foo", "bar";

is too subtle and error prone.

@dsnet
Copy link
Contributor Author

dsnet commented Jul 3, 2019

Also, the current behavior goes against the grammar specification, which says that the token should be a fieldName which is equivalent to the ident token.

Related: https://developers.google.com/protocol-buffers/docs/reference/proto3-spec#reserved

@mkruskal-google
Copy link
Member

mkruskal-google commented Sep 1, 2022

I think validating the reserved field names it a reasonable feature request. For the related problems, I don't see any unambiguous solution there other than education/documentation.

@jhump
Copy link
Contributor

jhump commented Sep 15, 2022

For the related problems, I don't see any unambiguous solution there other than education/documentation.

The parser could be updated to allow identifiers:

// unambiguous, omitting the comma is a syntax error
reserved foo, bar;

The existing support for string literals could remain, for backwards compatibility. (Though hopefully not forever?)

@fowles
Copy link
Member

fowles commented Sep 15, 2022

Given the way that reserved works for field numbers, using it this way with identifiers seems like a clean parallel structure. It can even be implemented in a way that avoids modifying descriptor.proto. Probably we should have a small design doc that outlines the alternatives. @mkruskal-google can you share a template with @jhump ?

@mkruskal-google
Copy link
Member

@jhump
Copy link
Contributor

jhump commented Sep 16, 2022

@mkruskal-google, I don't have permission to view that doc. Maybe it's Google-internal? Can you create a copy and make it globally readable?

@mkruskal-google
Copy link
Member

@jhump
Copy link
Contributor

jhump commented Oct 12, 2022

@mkruskal-google, I don't think this issue is resolved. We still need another step to actually change the warnings (merged in #10586) into actual errors. Can you re-open?

I'll go ahead and open a new issue to track the rest of the proposal, for allowing bare identifiers to be used instead of string literals.

Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Denotes the issue/PR has not seen activity in the last 90 days. label Apr 14, 2024
Copy link

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug inactive Denotes the issue/PR has not seen activity in the last 90 days. protoc
Projects
None yet
6 participants