[Easy] sanitizer.py: add utf-8 encoding and log invalid regex in .termstoryignore (fixes #297)#326
Conversation
|
Tip 👋 Hey @Mubashir78 — Miku's on it. Here are the most useful commands for this PR:
Note 🎓 This repo is part of ECSOC26. Run Note ⭐ Star this repo to unlock all commands. Say 📖 All commands🤖 AI-powered — 14 commands
🔧 Issue & PR management — 18 commands
🎉 Community & utility — 9 commands
|
294cc5f to
410babb
Compare
|
/rewrite |
|
miku ✅ PR description rewritten! Check the PR body above. PreviewSummaryThis PR fixes two robustness gaps in Changes
Fixes
TestingRun the existing sanitizer test suite to verify custom ignore rule loading still functions correctly: python -m pytest tests/test_sanitizer.py::test_custom_termstoryignore -vTo verify logging behavior, create a malformed echo "[invalid_regex" > ~/.termstoryignore
python -c "import termstory.sanitizer" # Should log warning about invalid regexNotesThe |
bitflicker64
left a comment
There was a problem hiding this comment.
Can you resolve conflicts? Thanks.
Uh what conflict? The greplite says 5/5 and can be merged safely. |
|
:miku /review-sc |
|
miku ✅ No mechanical fixes found. Reviewed 1 file(s). |
Dismissed because a newer commit was pushed; Greptile will re-review the current head.
|
/ecsoc /triage /approve /lgtm |
|
miku 🏷️ Added miku ✅ Marked as triaged ( miku ✅ Approved! 🎉 miku ✅ LGTM! Label added by @bitflicker64. Use |

Summary
This PR fixes two robustness gaps in
.termstoryignoreloading withintermstory/sanitizer.py: it pins file encoding to UTF-8 for consistent cross-platform decoding of non-ASCII patterns, and replaces silent error swallowing with explicit logging so invalid regex patterns and file-level I/O failures are now visible to operators. These changes improve debuggability and prevent silent misconfiguration of custom redaction rules.Changes
import loggingand initialized module-level logger intermstory/sanitizer.pyopen(path, 'r')toopen(path, 'r', encoding='utf-8')inload_custom_ignore_rules()to ensure consistent UTF-8 decoding across platformsexcept re.error: passwithexcept re.error as e: logger.warning("Invalid regex in %s line %r: %s", path, line, e)to log invalid regex patternsexcept Exception: passwithexcept Exception as e: logger.warning("Failed to load ignore rules from %s: %s", path, e)to log file-level failuresFixes
.termstoryignoreloadingTesting
Run the existing sanitizer test suite to verify custom ignore rule loading still functions correctly:
To verify logging behavior, create a malformed
.termstoryignorefile and check that warnings are emitted:Notes
The
load_custom_ignore_rules()function executes once at module import time, so changes to.termstoryignorestill require a TermStory restart to take effect . This is a documented limitation in SECURITY.md.