From 79c844c2a58cd84671db78ee063f6b9b5fd942bb Mon Sep 17 00:00:00 2001 From: omnom62 <75066712+omnom62@users.noreply.github.com> Date: Mon, 15 Sep 2025 19:40:12 +1000 Subject: Fixes to T7221 and greedy matching (#430) * Fixes to T7221 and greedy matching --- changelogs/fragments/t7701_greedy_starwith_fix.yml | 3 +++ plugins/cliconf/vyos.py | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/t7701_greedy_starwith_fix.yml diff --git a/changelogs/fragments/t7701_greedy_starwith_fix.yml b/changelogs/fragments/t7701_greedy_starwith_fix.yml new file mode 100644 index 00000000..1e6bdf59 --- /dev/null +++ b/changelogs/fragments/t7701_greedy_starwith_fix.yml @@ -0,0 +1,3 @@ +--- +bugfixes: + - cliconf/vyos.py - Fixed greedy matching in configuration parsing diff --git a/plugins/cliconf/vyos.py b/plugins/cliconf/vyos.py index 5beffaa1..c35ff1ec 100644 --- a/plugins/cliconf/vyos.py +++ b/plugins/cliconf/vyos.py @@ -234,7 +234,9 @@ class Cliconf(CliconfBase): set_format = candidate.startswith("set") or candidate.startswith("delete") candidate_obj = NetworkConfig(indent=4, contents=candidate) + if not set_format: + config = [c.line for c in candidate_obj.items] commands = list() # this filters out less specific lines @@ -248,6 +250,7 @@ class Cliconf(CliconfBase): candidate_commands = ["set %s" % cmd.replace(" {", "") for cmd in commands] else: + candidate_commands = str(candidate).strip().split("\n") if diff_match == "none": @@ -269,12 +272,14 @@ class Cliconf(CliconfBase): updates.append(line) elif item.startswith("delete"): + if not running_commands: updates.append(line) else: item = re.sub(r"delete", "set", item) + for entry in running_commands: - if entry.startswith(item) and line not in visited: + if re.match(rf"^{re.escape(item)}\b", entry) and line not in visited: updates.append(line) visited.add(line) -- cgit v1.2.3