File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -412,8 +412,14 @@ def _sanitize_error_message(message: str) -> str:
412412 """Sanitize error messages to remove sensitive information."""
413413 import re
414414
415- # Remove file paths (both Unix and Windows style)
416- message = re .sub (r"[/\\][^\s]*[/\\][^\s]*" , "[PATH]" , message )
415+ # Remove file paths but preserve filenames
416+ # Match paths with directories and capture the filename
417+ # Unix style: /path/to/file.py -> file.py
418+ message = re .sub (r"(/[^/\s]+)+/([^/\s]+)" , r"\2" , message )
419+ # Windows style: C:\path\to\file.py -> file.py
420+ message = re .sub (r"([A-Za-z]:\\[^\\]+\\)+([^\\]+)" , r"\2" , message )
421+ # Remaining absolute paths without filename
422+ message = re .sub (r"[/\\][^\s]*[/\\]" , "[PATH]/" , message )
417423
418424 # Remove potential API keys or tokens (common patterns)
419425 # Generic API keys (20+ alphanumeric with underscores/hyphens)
You can’t perform that action at this time.
0 commit comments