mirror of
https://github.com/protobufjs/protobuf.js.git
synced 2025-12-08 20:58:55 +00:00
Fixed: Properly parse nested textformat options, also tackles #655
This commit is contained in:
parent
27b16351f3
commit
ef7be352ba
2
dist/light/protobuf.js
vendored
2
dist/light/protobuf.js
vendored
@ -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
|
||||
*/
|
||||
|
||||
2
dist/light/protobuf.min.js
vendored
2
dist/light/protobuf.min.js
vendored
@ -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
|
||||
*/
|
||||
|
||||
BIN
dist/light/protobuf.min.js.gz
vendored
BIN
dist/light/protobuf.min.js.gz
vendored
Binary file not shown.
2
dist/minimal/protobuf.js
vendored
2
dist/minimal/protobuf.js
vendored
@ -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
|
||||
*/
|
||||
|
||||
2
dist/minimal/protobuf.min.js
vendored
2
dist/minimal/protobuf.min.js
vendored
@ -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
|
||||
*/
|
||||
|
||||
BIN
dist/minimal/protobuf.min.js.gz
vendored
BIN
dist/minimal/protobuf.min.js.gz
vendored
Binary file not shown.
32
dist/protobuf.js
vendored
32
dist/protobuf.js
vendored
@ -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 {
|
||||
|
||||
2
dist/protobuf.js.map
vendored
2
dist/protobuf.js.map
vendored
File diff suppressed because one or more lines are too long
6
dist/protobuf.min.js
vendored
6
dist/protobuf.min.js
vendored
File diff suppressed because one or more lines are too long
BIN
dist/protobuf.min.js.gz
vendored
BIN
dist/protobuf.min.js.gz
vendored
Binary file not shown.
2
dist/protobuf.min.js.map
vendored
2
dist/protobuf.min.js.map
vendored
File diff suppressed because one or more lines are too long
30
src/parse.js
30
src/parse.js
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user