Skip to content

Commit ca5f63e

Browse files
committed
fix the filename sanitization logic
1 parent c38a93e commit ca5f63e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

codeflash/tracing/tracing_new_process.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,14 +789,22 @@ def sanitize_to_filename(self, arg: str) -> str:
789789
arg = arg.replace("\n", "_").replace("\r", "_")
790790

791791
# Replace contiguous whitespace (including tabs and multiple spaces) with a single underscore
792-
arg = re.sub(r"\s+", "_", arg)
792+
# Limit to 5 whitespace splits
793+
parts = re.split(r"\s+", arg)
794+
if len(parts) > 5:
795+
parts = parts[:5]
796+
797+
arg = "_".join(parts)
793798

794799
# Remove all characters that are not alphanumeric, underscore, or dot
795800
arg = re.sub(r"[^\w._]", "", arg)
796801

797802
# Avoid filenames starting or ending with a dot or underscore
798803
arg = arg.strip("._")
799804

805+
# Limit to 100 characters
806+
arg = arg[:100]
807+
800808
# Fallback if resulting name is empty
801809
return arg or "untitled"
802810

0 commit comments

Comments
 (0)