From 85c97cc23a463c821ce650368c839a9572cb1c76 Mon Sep 17 00:00:00 2001 From: TejasLamba2006 Date: Wed, 11 Nov 2026 00:50:14 +0530 Subject: [PATCH] fix(microskills): guard parse_payload against wrongly-typed proposer fields - Handle extractors/facts as null (not just missing key) - Filter extractors with non-string pattern - Filter facts with non-dict detector - Guard _rx against non-string pattern input Fixes #173 --- tokeneconomizer/microskills/distiller.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tokeneconomizer/microskills/distiller.py b/tokeneconomizer/microskills/distiller.py index a1532ef..953b189 100644 --- a/tokeneconomizer/microskills/distiller.py +++ b/tokeneconomizer/microskills/distiller.py @@ -261,7 +261,7 @@ def proposer_view(dg): def _rx(pat): - if not pat: + if not pat or not isinstance(pat, str): return None try: return re.compile(pat) @@ -526,10 +526,10 @@ def parse_payload(raw): obj = json.loads(m.group(0)) except Exception: return [], [] - exts = [e for e in obj.get("extractors", []) - if isinstance(e, dict) and e.get("name") and e.get("pattern")] - facts = [f for f in obj.get("facts", []) - if isinstance(f, dict) and f.get("id") and f.get("detector")] + exts = [e for e in (obj.get("extractors") or []) + if isinstance(e, dict) and e.get("name") and isinstance(e.get("pattern"), str)] + facts = [f for f in (obj.get("facts") or []) + if isinstance(f, dict) and f.get("id") and isinstance(f.get("detector"), dict)] return exts, facts