Skip to content

Commit cc7d595

Browse files
authored
fix: Restore first-match namespace lookup (#2236)
1 parent 3abc9b5 commit cc7d595

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/namespace.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,10 @@ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
466466
// Otherwise try each nested namespace
467467
} else {
468468
for (var i = 0; i < this.nestedArray.length; ++i)
469-
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
469+
if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath))) {
470470
exact = found;
471+
break;
472+
}
471473
}
472474

473475
// Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.

tests/api_namespace.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,27 @@ tape.test("reflected namespaces", function(test) {
114114
test.equal(specialRoot.lookup("__proto__"), null, "should ignore reserved nested object names");
115115
test.equal(Object.getPrototypeOf(specialRoot._lookupCache), null, "should isolate lookup cache keys");
116116

117+
var fallbackRoot = protobuf.Root.fromJSON({
118+
nested: {
119+
A: {
120+
nested: {
121+
Point3D: { fields: {} }
122+
}
123+
},
124+
C: {
125+
nested: {
126+
Point3D: { fields: {} }
127+
}
128+
},
129+
B: {
130+
fields: {
131+
p: { type: "Point3D", id: 1 }
132+
}
133+
}
134+
}
135+
}).resolveAll();
136+
test.equal(fallbackRoot.lookupType("B").fields.p.resolvedType.fullName, ".A.Point3D", "should preserve legacy first-match nested fallback lookup");
137+
117138
ns = protobuf.Namespace.fromJSON("My", {
118139
nested: {
119140
Message: { fields: {} },

0 commit comments

Comments
 (0)