Skip to content

Commit

Permalink
Ignore optional commas in aggregate options
Browse files Browse the repository at this point in the history
More information on the "Aggregate Syntax" here:
protocolbuffers/protobuf#1148

These are accepted by the proto compiler but rarely used - I found an
example in the
[Cloud Endpoints docs](https://cloud.google.com/endpoints/docs/grpc-service-config/reference/rpc/google.api#google.api.HttpRule.FIELDS.string.google.api.HttpRule.rest_method_name).

Fixes #383.
  • Loading branch information
drigz committed Mar 15, 2018
1 parent 7c391d6 commit 1ff3701
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ function parse(source, root, options) {
else
setOption(parent, name + "." + token, readValue(true));
}
skip(",", true);
} while (!skip("}", true));
} else
setOption(parent, name, readValue(true));
Expand Down
2 changes: 2 additions & 0 deletions tests/comp_options-textformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ extend google.protobuf.FieldOptions {\
message Test {\
string value = 1 [(my_options) = { a: \"foo\" b: \"bar\" }];\
string value2 = 2 [(my_options) = { a: \"foo\" b { c: \"bar\" } }];\
string value3 = 3 [(my_options) = { a: \"foo\", b: \"bar\" }];\
}";

tape.test("options in textformat", function(test) {
var root = protobuf.parse(proto).root;
var Test = root.lookup("Test");
test.same(Test.fields.value.options, { "(my_options).a": "foo", "(my_options).b": "bar" }, "should parse correctly");
test.same(Test.fields.value2.options, { "(my_options).a": "foo", "(my_options).b.c": "bar" }, "should parse correctly when nested");
test.same(Test.fields.value3.options, { "(my_options).a": "foo", "(my_options).b": "bar" }, "should parse correctly when comma-separated");
test.end();
});

0 comments on commit 1ff3701

Please sign in to comment.