You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The parser has a special grammar for parsing default values that allows infinity, -infinity, and NaN. However, this grammar is not used when parsing other numeric option values.
Take the following example:
syntax="proto2";
import"google/protobuf/descriptor.proto";
extendgoogle.protobuf.MessageOptions {
optionalFoofoo=10101;
}
messageFoo {
optionaldoubleval=1 [default = -nan]; // "nan", "-nan", "inf", and "-inf" allowed hererepeatedfloatvals=2;
option(foo)= { val: -infINITY }; // aside: inside a message literal, anything goes 😭option(foo).vals= inf; // "nan", "-nan", "inf", and "-inf" NOT allowed here (??)// The above line results in the following error from protoc:// test.proto:15:23: Value must be number for float option "Foo.vals".// If the value were -inf (negative), the message changes:// test.proto:15:24: Invalid '-' symbol before identifier.
}
I assert that it's a bug that infinity and NaN can only be used in default values and not other option values. It seems like a simple overlooked thing that is easy to fix.
(As shown above, the contents of message literals, which are parsed using the text format, are very lenient. I'm certainly not suggesting that anything else in protoc should be that forgiving -- just pointing it out in the example since it's... interesting.)
The text was updated successfully, but these errors were encountered:
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.
…ffers#15017)
The parser already supports these values for the special "default" field option. But, inconsistently, does not support them for other options whose type is float or double. This addresses that inconsistency.
Fixesprotocolbuffers#15010.
Closesprotocolbuffers#15017
COPYBARA_INTEGRATE_REVIEW=protocolbuffers#15017 from jhump:jh/inf-and-nan-in-option-values 1f8217c
PiperOrigin-RevId: 627399259
The parser has a special grammar for parsing default values that allows infinity, -infinity, and NaN. However, this grammar is not used when parsing other numeric option values.
Take the following example:
I assert that it's a bug that infinity and NaN can only be used in default values and not other option values. It seems like a simple overlooked thing that is easy to fix.
(As shown above, the contents of message literals, which are parsed using the text format, are very lenient. I'm certainly not suggesting that anything else in
protoc
should be that forgiving -- just pointing it out in the example since it's... interesting.)The text was updated successfully, but these errors were encountered: