From 2c8677b6e8ce9cd41f2223db402ef295f54a8419 Mon Sep 17 00:00:00 2001 From: MarekWo Date: Mon, 29 Dec 2025 08:29:59 +0100 Subject: [PATCH] fix(bridge): Improve pending_contacts parser to filter JSON lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: Parser incorrectly matched JSON lines (adverts, GRP_TXT messages) as pending contacts because they contained colons. This caused false positives like {"raw_hex": "..."} being parsed as contact name. Root cause: meshcli outputs JSON for received messages (due to json_log_rx=on setting) during pending_contacts command execution. Original parser only checked for ':' presence, matching any JSON. Solution: Added robust filtering before parsing: 1. Skip empty lines 2. Skip JSON lines (starting with { or [) 3. Skip meshcli prompt lines (ending with |*) 4. Validate public_key contains only hex characters (0-9, a-f, A-F) This ensures only valid "ContactName: " format is parsed. Example of filtered content: - SKIP: {"raw_hex": "25bc...", "payload_typename": "GRP_TXT"} - SKIP: MarWoj|* - PARSE: Skyllancer: f9ef123abc456... Testing: No false positives with JSON lines in output. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 --- meshcore-bridge/bridge.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/meshcore-bridge/bridge.py b/meshcore-bridge/bridge.py index 504253c..f5f177c 100644 --- a/meshcore-bridge/bridge.py +++ b/meshcore-bridge/bridge.py @@ -539,13 +539,28 @@ def get_pending_contacts(): if stdout: for line in stdout.split('\n'): line = line.strip() + + # Skip empty lines + if not line: + continue + + # Skip JSON lines (adverts, messages, or other JSON output from meshcli) + if line.startswith('{') or line.startswith('['): + continue + + # Skip meshcli prompt lines (e.g., "MarWoj|*") + if line.endswith('|*'): + continue + # Parse lines with format: "Name: " if ':' in line: parts = line.split(':', 1) if len(parts) == 2: name = parts[0].strip() public_key = parts[1].strip().replace(' ', '') # Remove spaces from hex - if name and public_key: + + # Additional validation: pubkey should be hex characters only + if name and public_key and all(c in '0123456789abcdefABCDEF' for c in public_key): pending.append({ 'name': name, 'public_key': public_key