diff --git a/src/parse.js b/src/parse.js index 739f3265e..147dc7e90 100644 --- a/src/parse.js +++ b/src/parse.js @@ -639,13 +639,18 @@ function parse(source, root, options) { value = []; var lastValue; if (skip("[", true)) { - do { - lastValue = readValue(true); - value.push(lastValue); - } while (skip(",", true)); - skip("]"); - if (typeof lastValue !== "undefined") { - setOption(parent, name + "." + token, lastValue); + if (peek() === "]") { + setOption(parent, name, "." + token, []); + next(); + } else { + do { + lastValue = readValue(true); + value.push(lastValue); + } while (skip(",", true)); + skip("]"); + if (typeof lastValue !== "undefined") { + setOption(parent, name + "." + token, lastValue); + } } } } else { diff --git a/tests/comp_options-parse.js b/tests/comp_options-parse.js index ed4a00572..35de46592 100644 --- a/tests/comp_options-parse.js +++ b/tests/comp_options-parse.js @@ -134,6 +134,7 @@ tape.test("Options", function (test) { { "(method_rep_msg)": { value: 1, + empty_repeated: [], nested: {nested: {value: "x"}}, rep_nested: [{value: "y"}, {value: "z"}], rep_value: 3 diff --git a/tests/data/options_test.proto b/tests/data/options_test.proto index 52f022818..ede3334fd 100644 --- a/tests/data/options_test.proto +++ b/tests/data/options_test.proto @@ -119,6 +119,7 @@ service TestOptionsService { rpc TestOptionsRpc(Msg) returns (Msg) { option (method_rep_msg) = { value: 1 + empty_repeated: [] nested { nested { value: "x"