sd-bus: add comment and test in sd_bus_path_decode() for empty string
3970 e = object_path_startswith(path, prefix); (gdb) p path $1 = 0x55c5a166f768 "/org/freedesktop/portable1/image" (gdb) p prefix $2 = 0x55c59ffc2928 "/org/freedesktop/portable1/image" (gdb) p e $1 = 0x5581a1675788 "" This can be a bit confusing in certain cases, so add a comment and a test to make the behaviour clearer and explicit.
This commit is contained in:
committed by
Yu Watanabe
parent
cd532c633f
commit
54cd2d6869
@@ -3973,6 +3973,10 @@ _public_ int sd_bus_path_decode(const char *path, const char *prefix, char **ext
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Note that 'e' might be an empty string here. That's expected. E.g. a case where the subtree
|
||||
* corresponds to a subtree on a disk, and we want to return something that represents the root
|
||||
* of the filesystem. */
|
||||
|
||||
ret = bus_label_unescape(e);
|
||||
if (!ret)
|
||||
return -ENOMEM;
|
||||
|
||||
@@ -36,7 +36,7 @@ static void test_bus_path_encode_unique(void) {
|
||||
}
|
||||
|
||||
static void test_bus_path_encode(void) {
|
||||
_cleanup_free_ char *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *f = NULL;
|
||||
_cleanup_free_ char *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *f = NULL, *g = NULL;
|
||||
|
||||
assert_se(sd_bus_path_encode("/foo/bar", "waldo", &a) >= 0 && streq(a, "/foo/bar/waldo"));
|
||||
assert_se(sd_bus_path_decode(a, "/waldo", &b) == 0 && b == NULL);
|
||||
@@ -50,6 +50,8 @@ static void test_bus_path_encode(void) {
|
||||
|
||||
assert_se(sd_bus_path_encode("/foo/bar", "foo.bar", &e) >= 0 && streq(e, "/foo/bar/foo_2ebar"));
|
||||
assert_se(sd_bus_path_decode(e, "/foo/bar", &f) > 0 && streq(f, "foo.bar"));
|
||||
|
||||
assert_se(sd_bus_path_decode("/waldo", "/waldo", &g) > 0 && streq(g, ""));
|
||||
}
|
||||
|
||||
static void test_bus_path_encode_many(void) {
|
||||
|
||||
Reference in New Issue
Block a user