From c0314588585399403b906d966e6cef5b12a0a1ee Mon Sep 17 00:00:00 2001 From: Iustin Pop Date: Wed, 16 May 2012 01:11:13 +0200 Subject: [PATCH] Fix bug in get_all for empty namespace handling Also add an unit test for it. --- test/test_xattr.py | 9 ++++++++- xattr.c | 13 +++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/test/test_xattr.py b/test/test_xattr.py index fa2c288..4c0c0bc 100644 --- a/test/test_xattr.py +++ b/test/test_xattr.py @@ -12,8 +12,10 @@ from xattr import NS_USER, XATTR_CREATE, XATTR_REPLACE if sys.hexversion >= 0x03000000: PY3K = True + EMPTY_NS = b'' else: PY3K = False + EMPTY_NS = '' TEST_DIR = os.environ.get("TESTDIR", ".") @@ -126,7 +128,11 @@ class xattrTest(unittest.TestCase): self.assertRaises(EnvironmentError, xattr.set, item, self.USER_NN, self.USER_VAL, flags=XATTR_CREATE, namespace=NS_USER) - self.assertEqual(xattr.list(item, nofollow=symlink), [self.USER_ATTR]) + self.assertEqual(xattr.list(item, nofollow=symlink), + [self.USER_ATTR]) + self.assertEqual(xattr.list(item, nofollow=symlink, + namespace=EMPTY_NS), + [self.USER_ATTR]) self.assertEqual(xattr.list(item, namespace=NS_USER, nofollow=symlink), [self.USER_NN]) self.assertEqual(xattr.get(item, self.USER_ATTR, nofollow=symlink), @@ -345,6 +351,7 @@ class xattrTest(unittest.TestCase): VN = [self.USER_NN] for i in range(self.MANYOPS_COUNT): self.assertEqual(xattr.list(fh), VL) + self.assertEqual(xattr.list(fh, namespace=EMPTY_NS), VL) self.assertEqual(xattr.list(fh, namespace=NS_USER), VN) for i in range(self.MANYOPS_COUNT): self.assertEqual(xattr.get(fh, self.USER_ATTR), self.USER_VAL) diff --git a/xattr.c b/xattr.c index 52965e8..b6bead0 100644 --- a/xattr.c +++ b/xattr.c @@ -222,15 +222,16 @@ static int _remove_obj(target_t *tgt, const char *name) { /* Checks if an attribute name matches an optional namespace. - If the namespace is NULL, it will return the name itself. If the - namespace is non-NULL and the name matches, it will return a - pointer to the offset in the name after the namespace and the - separator. If however the name doesn't match the namespace, it will - return NULL. + If the namespace is NULL or an empty string, it will return the + name itself. If the namespace is non-NULL and the name matches, it + will return a pointer to the offset in the name after the namespace + and the separator. If however the name doesn't match the namespace, + it will return NULL. + */ const char *matches_ns(const char *ns, const char *name) { size_t ns_size; - if (ns == NULL) + if (ns == NULL || *ns == '\0') return name; ns_size = strlen(ns); -- 2.39.5