Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: type names can be split into multiple tokens #1877

Merged
merged 1 commit into from Mar 27, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/parse.js
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
@@ -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
@@ -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;
}