Standardize fuzzy matching and use fullmatch

Solves two problems:

1. How match fuzziness was used was very inconsistent; make them all the
same, i.e. "if is_fuzzy and limit, apply .* to both sides".

2. Use re.fullmatch instead of re.match to ensure exact matching of the
regex to the value. Without fuzziness, this would sometimes cause
inconsistent behavior, for instance if a limit was non-fuzzy "vm",
expecting to match the actual "vm", but also matching "vm1" too.
This commit is contained in:
2021-12-06 16:35:29 -05:00
parent 2461941421
commit c776aba8b3
4 changed files with 50 additions and 54 deletions

View File

@ -237,13 +237,17 @@ def get_list(
node_list = []
full_node_list = zkhandler.children("base.node")
if is_fuzzy and limit:
# Implicitly assume fuzzy limits
if not re.match(r"\^.*", limit):
limit = ".*" + limit
if not re.match(r".*\$", limit):
limit = limit + ".*"
for node in full_node_list:
if limit:
try:
if not is_fuzzy:
limit = "^" + limit + "$"
if re.match(limit, node):
if re.fullmatch(limit, node):
node_list.append(getNodeInformation(zkhandler, node))
except Exception as e:
return False, "Regex Error: {}".format(e)