diff --git a/src/parse.js b/src/parse.js index 0e538be0b..ad392da18 100644 --- a/src/parse.js +++ b/src/parse.js @@ -608,7 +608,7 @@ function parse(source, root, options) { // }; value = []; var lastValue; - if (skip("[", true)) { + if (skip("[", true) && !skip("]", true)) { do { lastValue = readValue(true); value.push(lastValue); diff --git a/tests/comp_options-parse.js b/tests/comp_options-parse.js index 18690a424..6e4c38ebc 100644 --- a/tests/comp_options-parse.js +++ b/tests/comp_options-parse.js @@ -45,11 +45,21 @@ tape.test("Options", function (test) { {"(mo_rep_msg)": {value: 1, rep_value: [2, 3]}}, {"(mo_rep_msg)": {value: 4, rep_value: [5, 6]}}, {"(mo_rep_msg)": {value: 5, rep_value: [7, 8]}}, + {"(mo_rep_msg)": {rep_value: []}}, {"(mo_single_msg)": {value: 7, rep_value: [8, 9]}}, ], "should take all message options"); test.end(); }); + test.test(test.name + " - message options (Empty)", function (test) { + var TestMessageOptionsMsg = root.lookup("TestMessageOptionsEmpty"); + test.equal("(mo_rep_msg).rep_value" in TestMessageOptionsMsg.options, false, "should treat empty repeated option as missing"); + test.same(TestMessageOptionsMsg.parsedOptions, [ + {"(mo_rep_msg)": {value: 1, rep_value: []}}, + ], "should parse empty options correctly"); + test.end(); + }); + test.test(test.name + " - field options (Nested)", function (test) { var TestFieldOptionsNested = root.lookup("TestFieldOptionsNested"); test.equal(TestFieldOptionsNested.fields.field1.options["(fo_rep_msg).value"], 1, "should merge repeated options messages"); diff --git a/tests/data/options_test.proto b/tests/data/options_test.proto index 52f022818..18926814d 100644 --- a/tests/data/options_test.proto +++ b/tests/data/options_test.proto @@ -78,11 +78,21 @@ message TestMessageOptionsMsg { value: 5 rep_value: [ 7, 8 ] }; + option (mo_rep_msg) = { + rep_value: [ ] + }; option (mo_single_msg).value = 7; option (mo_single_msg).rep_value = 8; option (mo_single_msg).rep_value = 9; } +message TestMessageOptionsEmpty { + option (mo_rep_msg) = { + value: 1 + rep_value: [ ] + }; +} + message TestFieldOptionsNested { string field1 = 1 [(fo_rep_msg) = {value: 1 nested { nested {value: "x"} } rep_nested { value: "y"} rep_nested { value: "z" } rep_value: 3}, (fo_rep_msg) = { nested { value: "w" }}]; string field2 = 2 [(fo_single_msg).nested.value = "x", (fo_single_msg).rep_nested = {value : "x"}, (fo_single_msg).rep_nested = {value : "y"}];