Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,16 @@ function parse(source, root, options) {
parseGroup(parent, rule);
return;
}
// Type names can consume multiple tokens, in multiple variants:
// package.subpackage field tokens: "package.subpackage" [TYPE NAME ENDS HERE] "field"
// package . subpackage field tokens: "package" "." "subpackage" [TYPE NAME ENDS HERE] "field"
// package. subpackage field tokens: "package." "subpackage" [TYPE NAME ENDS HERE] "field"
// package .subpackage field tokens: "package" ".subpackage" [TYPE NAME ENDS HERE] "field"
// Keep reading tokens until we get a type name with no period at the end,
// and the next token does not start with a period.
while (type.endsWith(".") || peek().startsWith(".")) {
type += next();
}

/* istanbul ignore if */
if (!typeRefRe.test(type))
Expand Down
14 changes: 14 additions & 0 deletions tests/comp_whitespace-in-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var tape = require("tape");
var protobuf = require("..");

tape.test("parsing line breaks", function (test) {

test.test(test.name + " - field options (Int)", function (test) {
var root = protobuf.loadSync("tests/data/whitespace-in-type.proto");
var message = root.lookupType('some.really.long.name.which.does.not.really.make.any.sense.but.sometimes.we.still.see.stuff.like.this.WouldYouParseThisForMePlease');
test.equal(message.fields.field.type, 'some.really.long.name.which.does.not.really.make.any.sense.but.sometimes.we.still.see.stuff.like.this.Test');
test.end();
});

test.end();
});
16 changes: 16 additions & 0 deletions tests/data/whitespace-in-type.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
syntax = "proto3";

package some.really.long.name.which.does.not.really.make.any.sense.but.sometimes.we.still.see.stuff.like.this;

message WouldYouParseThisForMePlease {
optional some.really.long. name . which . does .not
.really.make.any. sense.but.
sometimes.we.still
.
see.stuff .like.this
.Test field = 1;
}

message Test {
string field = 1;
}