From 410babb8754a4a65046c831d374af90030f2da1c Mon Sep 17 00:00:00 2001 From: Mubashir78 Date: Sat, 18 Jul 2026 19:50:52 +0000 Subject: [PATCH] fix: add utf-8 encoding and log invalid regex in .termstoryignore loading (fixes #297) --- termstory/sanitizer.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/termstory/sanitizer.py b/termstory/sanitizer.py index 0fb169b..9ad0529 100644 --- a/termstory/sanitizer.py +++ b/termstory/sanitizer.py @@ -1,8 +1,11 @@ +import logging import re import os import math from typing import List, Tuple, Optional +logger = logging.getLogger(__name__) + # Load custom redaction patterns from .termstoryignore # IMPORTANT: This loads once at module import time (called at the bottom of this file). # Edits to ~/.termstoryignore take effect only after restarting TermStory — there is no @@ -17,16 +20,16 @@ def load_custom_ignore_rules(): for path in paths: if os.path.exists(path): try: - with open(path, 'r') as f: + with open(path, 'r', encoding='utf-8') as f: for line in f: line = line.strip() if line and not line.startswith('#'): try: CUSTOM_REDACTION_PATTERNS.append(re.compile(line, re.IGNORECASE)) - except re.error: - pass - except Exception: - pass + except re.error as e: + logger.warning("Invalid regex in %s line %r: %s", path, line, e) + except Exception as e: + logger.warning("Failed to load ignore rules from %s: %s", path, e) load_custom_ignore_rules() # Blacklist patterns - if a command matches any of these, the entire session is dropped from AI