From 7da5d44caacecd9af2f8198e7403d7d043c87579 Mon Sep 17 00:00:00 2001 From: mriemensberger <98171222+mriemensberger@users.noreply.github.com> Date: Wed, 8 May 2024 21:56:13 +0200 Subject: [PATCH] fix: introspection bogus child paths (#280) --- src/dbus_fast/message_bus.py | 3 +++ tests/service/test_standard_interfaces.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dbus_fast/message_bus.py b/src/dbus_fast/message_bus.py index bc6d0ee9..14776fb5 100644 --- a/src/dbus_fast/message_bus.py +++ b/src/dbus_fast/message_bus.py @@ -664,6 +664,9 @@ def _introspect_export_path(self, path: str) -> intr.Node: continue child_path = export_path.split(path, maxsplit=1)[1] + if path != "/" and child_path and child_path[0] != "/": + continue + child_path = child_path.lstrip("/") child_name = child_path.split("/", maxsplit=1)[0] diff --git a/tests/service/test_standard_interfaces.py b/tests/service/test_standard_interfaces.py index 83ed6bc6..731d6739 100644 --- a/tests/service/test_standard_interfaces.py +++ b/tests/service/test_standard_interfaces.py @@ -91,6 +91,7 @@ async def test_introspect_matching_sub_paths(): interface = ExampleInterface("test.interface1") bus1.export("/a/test/path1", interface) + bus1.export("/a/test/path10", interface) bus1.export("/a/subpath/a/test/path2", interface) async def introspect_subpath(path, expected_subnodes): @@ -108,8 +109,9 @@ async def introspect_subpath(path, expected_subnodes): await introspect_subpath("/", {"a"}) await introspect_subpath("/a", {"test", "subpath"}) - await introspect_subpath("/a/test", {"path1"}) + await introspect_subpath("/a/test", {"path1", "path10"}) await introspect_subpath("/a/test/path1", set()) + await introspect_subpath("/a/test/path10", set()) await introspect_subpath("/a/subpath/a/test", {"path2"}) await introspect_subpath("/a/subpath/a/test/path2", set())