Skip to content

Commit

Permalink
Properly parse text format options + simple test case, fixes #636
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Jan 10, 2017
1 parent fe4d97b commit 7e57f4c
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/noparse/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/noparse/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/noparse/protobuf.min.js.gz
Binary file not shown.
7 changes: 3 additions & 4 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/runtime/protobuf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/runtime/protobuf.min.js.gz
Binary file not shown.
5 changes: 2 additions & 3 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,10 @@ function parse(source, root, options) {
if (!isName(token))
throw illegal(token, "name");

name = name + "." + token;
if (skip(":", true))
setOption(parent, name, readValue(true));
setOption(parent, name + "." + token, readValue(true));
else
parseOptionValue(parent, name);
parseOptionValue(parent, name + "." + token);
}
} else
setOption(parent, name, readValue(true));
Expand Down
15 changes: 15 additions & 0 deletions tests/data/options-textformat.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
syntax = "proto3";
import "google/protobuf/descriptor.proto";

message MyOptions {
string a = 1;
string b = 2;
}

extend google.protobuf.FieldOptions {
MyOptions my_options = 50000;
}

message Test {
string value = 1 [(my_options) = { a: "foo" b: "bar" }];
}
15 changes: 15 additions & 0 deletions tests/options-textformat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var tape = require("tape");

var protobuf = require("..");

tape.test("options in textformat", function(test) {

protobuf.load("tests/data/options-textformat.proto", function(err, root) {
if (err)
throw err;
var Test = root.lookup("Test");
test.same(Test.fields.value.options, { "(my_options).a": "foo", "(my_options).b": "bar" }, "should parse correctly");
test.end();
});

});

0 comments on commit 7e57f4c

Please sign in to comment.