Skip to content

fix: fix when package equal service name #1501

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChe
return found;

// Otherwise try each nested namespace
} else
for (var i = 0; i < this.nestedArray.length; ++i)
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i].lookup(path, filterTypes, true)))
return found;
}
for (var i = 0; i < this.nestedArray.length; ++i)
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i].lookup(path, filterTypes, true)))
return found;

// If there hasn't been a match, try again at the parent
if (this.parent === null || parentAlreadyChecked)
Expand Down
27 changes: 27 additions & 0 deletions tests/api_dup_service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const tape = require("tape");

const protobuf = require("..");

const proto = `
package greeter;

syntax = "proto2";

service greeter {
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
optional string name = 1;
}
message HelloReply {
optional string message = 1;
}
`
tape.test("test when package name is the same with service name", function(test) {

const root = protobuf.parse(proto).root;

test.ok(root.lookupService("greeter"), "should lookup services");

test.end();
});
4 changes: 1 addition & 3 deletions tests/api_namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ tape.test("reflected namespaces", function(test) {

test.equal(ns.get("Msg").lookupTypeOrEnum("Enm"), ns.lookup(".ns.Msg.Enm"), "should lookup the nearest type or enum");

test.throws(function() {
ns.lookupType("Enm");
}, Error, "should throw when looking up an enum as a type");
test.ok(ns.lookupType('Enm'), "should lokkup type in nest message");

test.throws(function() {
ns.lookupType("NOTFOUND");
Expand Down