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

This commit is contained in:
dcodeIO 2017-01-21 23:48:48 +01:00
parent 27b16351f3
commit ef7be352ba
14 changed files with 48 additions and 36 deletions

View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.6.0 (c) 2016, Daniel Wirtz
* Compiled Sat, 21 Jan 2017 18:41:01 UTC
* Compiled Sat, 21 Jan 2017 22:47:16 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/

View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.6.0 (c) 2016, Daniel Wirtz
* Compiled Sat, 21 Jan 2017 18:41:01 UTC
* Compiled Sat, 21 Jan 2017 22:47:16 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/

Binary file not shown.

View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.6.0 (c) 2016, Daniel Wirtz
* Compiled Sat, 21 Jan 2017 18:41:01 UTC
* Compiled Sat, 21 Jan 2017 22:47:16 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/

View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.6.0 (c) 2016, Daniel Wirtz
* Compiled Sat, 21 Jan 2017 18:41:01 UTC
* Compiled Sat, 21 Jan 2017 22:47:16 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/

Binary file not shown.

32
dist/protobuf.js vendored
View File

@ -1,6 +1,6 @@
/*!
* protobuf.js v6.6.0 (c) 2016, Daniel Wirtz
* Compiled Sat, 21 Jan 2017 18:41:01 UTC
* Compiled Sat, 21 Jan 2017 22:47:16 UTC
* Licensed under the BSD-3-Clause License
* see: https://github.com/dcodeIO/protobuf.js for details
*/
@ -3850,24 +3850,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 {

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -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 {

View File

@ -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();
});

View File

@ -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;