fix(bridge): Improve pending_contacts parser to filter JSON lines

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: <hex_pubkey>" 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 <noreply@anthropic.com>
This commit is contained in:
MarekWo
2025-12-29 08:29:59 +01:00
parent c0f6fd7dfc
commit 2c8677b6e8

View File

@@ -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: <hex_public_key>"
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