File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -110,12 +110,20 @@ def sanitize_filename(filename: str) -> str:
110
110
# 255 - len(os.getcwd()) - len("\\gpt-researcher\\outputs\\") - len("task_") - len(timestamp) - len("_.json") - safety_margin
111
111
max_task_length = 255 - len (os .getcwd ()) - 24 - 5 - 10 - 6 - 5 # ~189 chars for task
112
112
113
- # Truncate task if needed
114
- truncated_task = task [:max_task_length ] if len (task ) > max_task_length else task
115
-
113
+ # Truncate task if needed (by bytes)
114
+ truncated_task = ""
115
+ byte_count = 0
116
+ for char in task :
117
+ char_bytes = len (char .encode ('utf-8' ))
118
+ if byte_count + char_bytes <= max_task_length :
119
+ truncated_task += char
120
+ byte_count += char_bytes
121
+ else :
122
+ break
123
+
116
124
# Reassemble and clean the filename
117
125
sanitized = f"{ prefix } _{ timestamp } _{ truncated_task } "
118
- return re .sub (r"[^\w\s -]" , "" , sanitized ).strip ()
126
+ return re .sub (r"[^\w-]" , "" , sanitized ).strip ()
119
127
120
128
121
129
async def handle_start_command (websocket , data : str , manager ):
You can’t perform that action at this time.
0 commit comments