There was an error while loading. Please reload this page.
1 parent 45d6caf commit 14ce5a3Copy full SHA for 14ce5a3
2 files changed
src/basic_memory/importers/utils.py
@@ -5,15 +5,18 @@
5
from typing import Any
6
7
8
-def clean_filename(name: str) -> str: # pragma: no cover
+def clean_filename(name: str | None) -> str: # pragma: no cover
9
"""Clean a string to be used as a filename.
10
11
Args:
12
- name: The string to clean.
+ name: The string to clean (can be None).
13
14
Returns:
15
A cleaned string suitable for use as a filename.
16
"""
17
+ # Handle None or empty input
18
+ if not name:
19
+ return "untitled"
20
# Replace common punctuation and whitespace with underscores
21
name = re.sub(r"[\s\-,.:/\\\[\]\(\)]+", "_", name)
22
# Remove any non-alphanumeric or underscore characters
tests/importers/test_importer_utils.py
@@ -23,6 +23,9 @@ def test_clean_filename():
23
# Test with empty string
24
assert clean_filename("") == "untitled"
25
26
+ # Test with None (fixes #451 - ChatGPT null titles)
27
+ assert clean_filename(None) == "untitled"
28
+
29
# Test with only special characters
30
# Some implementations may return empty string or underscore
31
result = clean_filename("!@#$%^&*()")
0 commit comments