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:
@ -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)
|
||||
|
Reference in New Issue
Block a user