dbusjs / node-dbus-next

🚌 The next great dbus library for node
https://www.npmjs.com/package/dbus-next
155 stars 52 forks source link

Bug: Nodes not added to ProxyObject with root path ("/") #122

Open bspot opened 1 year ago

bspot commented 1 year ago

When creating a ProxyObject at the root path, i.e.

const obj = await bus.getProxyObject('some.service.name', '/');

the sub-nodes contained in the XML returned by the introspect call will not be added to the ProxyObject's nodes attribute.

That is because of how the sub-nodes full object path is constructed in https://github.com/dbusjs/node-dbus-next/blob/master/lib/client/proxy-object.js#L95

const path = `${this.path}/${name}`;
if (isObjectPathValid(path)) {
  this.nodes.push(path);
}

Since this.path is /, the sub-nodes path will start with //, which is not a valid object path and therefore rejected by the following isObjectPathValid check.

I think this could be replaced with

const path = this.path === '/' ? `/${name}` : `${this.path}/${name}`;

since otherwise object paths can not end with '/'.