diff --git a/src/namespace.js b/src/namespace.js index de9f4cdb0..753ad13ab 100644 --- a/src/namespace.js +++ b/src/namespace.js @@ -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) diff --git a/tests/api_dup_service.js b/tests/api_dup_service.js new file mode 100644 index 000000000..189507f92 --- /dev/null +++ b/tests/api_dup_service.js @@ -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(); +}); diff --git a/tests/api_namespace.js b/tests/api_namespace.js index b7203da68..ba3785620 100644 --- a/tests/api_namespace.js +++ b/tests/api_namespace.js @@ -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");