Permalink
Browse files

Fixed: Properly parse nested textformat options, also tackles #655

  • Loading branch information...
dcodeIO committed Jan 21, 2017
1 parent 27b1635 commit ef7be352baaec26bdcdce01a71fbee47bbdeec15

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
BIN +1 Byte (100%) dist/light/protobuf.min.js.gz
Binary file not shown.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
BIN +0 Bytes (100%) dist/minimal/protobuf.min.js.gz
Binary file not shown.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
BIN +27 Bytes (100%) dist/protobuf.min.js.gz
Binary file not shown.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -494,24 +494,28 @@ function parse(source, root, options) {
}
function parseOptionValue(parent, name) {
if (skip("{", true)) {
while ((token = next()) !== "}") {
/* istanbul ignore next */
if (!isName(token))
if (skip("{", true)) { // { a: "foo" b { c: "bar" } }
/* istanbul ignore next */
do {
if (!isName(token = next()))
throw illegal(token, "name");
skip(":");
// if (skip(":", true))
parent.setOption(name + "." + token, readValue(true));
// else
// parseOptionValue(parent, name + "." + token);
}
if (peek() === "{")
parseOptionValue(parent, name + "." + token);
else {
skip(":");
setOption(parent, name + "." + token, readValue(true));
}
} while (!skip("}", true));
} else
parent.setOption(name, readValue(true));
setOption(parent, name, readValue(true));
// Does not enforce a delimiter to be universal
}
function setOption(parent, name, value) {
if (parent.setOption)
parent.setOption(name, value);
}
function parseInlineOptions(parent) {
if (skip("[", true)) {
do {
@@ -13,11 +13,13 @@ 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\" } }];\
}";
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.end();
});
@@ -41,6 +41,8 @@ enum Test3;
enum Test4{
option (custom).foo = "";
ONE = 1 [foo="bar"];
TWO = 2 [(my_options) = { a: "foo" b { c: "bar" } }];
};
service Test5;

0 comments on commit ef7be35

Please sign in to comment.