From 969edeab865c9c71292b07bb91f4de1f6a1ff5a4 Mon Sep 17 00:00:00 2001 From: malmert Date: Sun, 1 Mar 2026 00:08:56 +0100 Subject: [PATCH] test without handle --- backend/src/api/nft_manager.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/backend/src/api/nft_manager.py b/backend/src/api/nft_manager.py index 1505ec6..73199d7 100644 --- a/backend/src/api/nft_manager.py +++ b/backend/src/api/nft_manager.py @@ -324,6 +324,18 @@ def parse_ruleset_text(nft_text: str) -> Dict[Tuple[str, str, str], List[Dict[st return result +def clean_rule_line(line: str) -> str: + """ + Remove trailing ' # handle ' from a textual rule line. + This strips the handle comment part while preserving the rest of the line. + """ + if not line: + return line + # remove ' # handle 123' optionally preceded by spaces and possibly at end-of-line + cleaned = re.sub(r"\s+#\s*handle\s*\d+\b\s*$", "", line) + return cleaned + + def populate_text_from_ruleset_text(custom: Dict[str, Any], nft_text: str) -> None: """ Enrich JSON-derived 'custom' structure in-place by setting only rule['text'] @@ -380,11 +392,12 @@ def populate_text_from_ruleset_text(custom: Dict[str, Any], nft_text: str) -> No break if mapped is not None: - # ensure we only write a str into 'text' + # clean the handle fragment from the textual line before storing try: - rule["text"] = str(mapped) + cleaned = clean_rule_line(str(mapped)) + rule["text"] = cleaned except Exception: - rule["text"] = mapped # should be str already + rule["text"] = mapped # fallback (should be str) # ---------- Normalization helper (lightweight and safe) ----------