diff --git a/backend/src/api/nft_api.py b/backend/src/api/nft_api.py index 7805dfd..b96d913 100644 --- a/backend/src/api/nft_api.py +++ b/backend/src/api/nft_api.py @@ -393,7 +393,14 @@ def nft_list_rules(table: str = DEFAULT_TABLE, chain: str = DEFAULT_CHAIN) -> Di nft_rule_text_full = text_map[handle] # remove trailing ' handle N' to get copy/paste clause m = HANDLE_RE.search(nft_rule_text_full) - nft_rule_text = nft_rule_text_full[: m.start()].strip() if m else nft_rule_text_full + if m: + # slice everything before ' handle N' + raw_clause = nft_rule_text_full[: m.start()].strip() + else: + raw_clause = nft_rule_text_full + # remove a trailing lone '#' (and surrounding whitespace) if present + # e.g. "meta iifname \"eth0\" # " -> "meta iifname \"eth0\"" + nft_rule_text = re.sub(r"\s*#\s*$", "", raw_clause).strip() add_command = f"add rule {table_name} {chain_name} {nft_rule_text}".strip() if nft_rule_text else None logger.debug("Attached textual rule for handle %s", handle) else: