Commit 3a541d90 authored by Iustin Pop's avatar Iustin Pop
Browse files

Fix utils.MatchNameComponent for full matches

While ‘test1’ matches both ‘test1’ and ‘test1.example’, it has a full,
exact match and we should return it if that is the case.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarMichael Hanselmann <>
parent 0f828357
......@@ -497,7 +497,8 @@ def MatchNameComponent(key, name_list):
this list, I{'test1'} as well as I{'test1.example'} will match, but
not I{'test1.ex'}. A multiple match will be considered as no match
at all (e.g. I{'test1'} against C{['',
'']}), except when the key fully matches an entry
(e.g. I{'test1'} against C{['test1', '']}).
@type key: str
@param key: the name to be searched
......@@ -509,6 +510,8 @@ def MatchNameComponent(key, name_list):
otherwise the element from the list which matches
if key in name_list:
return key
mo = re.compile("^%s(\..*)?$" % re.escape(key))
names_filtered = [name for name in name_list if mo.match(name) is not None]
if len(names_filtered) != 1:
......@@ -328,6 +328,14 @@ class TestMatchNameComponent(unittest.TestCase):
for key in "test1", "test1.example":
self.failUnlessEqual(MatchNameComponent(key, mlist), None)
def testFullMatch(self):
"""Test that a full match is returned correctly"""
key1 = "test1"
key2 = "test1.example"
mlist = [key2, key2 + ".com"]
self.failUnlessEqual(MatchNameComponent(key1, mlist), None)
self.failUnlessEqual(MatchNameComponent(key2, mlist), key2)
class TestFormatUnit(unittest.TestCase):
"""Test case for the FormatUnit function"""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment