Skip to content

Commit 14ce5a3

Browse files
phernandezclaude
andauthored
fix: handle null titles in ChatGPT import (#475)
Signed-off-by: phernandez <[email protected]> Co-authored-by: Claude <[email protected]>
1 parent 45d6caf commit 14ce5a3

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/basic_memory/importers/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,18 @@
55
from typing import Any
66

77

8-
def clean_filename(name: str) -> str: # pragma: no cover
8+
def clean_filename(name: str | None) -> str: # pragma: no cover
99
"""Clean a string to be used as a filename.
1010
1111
Args:
12-
name: The string to clean.
12+
name: The string to clean (can be None).
1313
1414
Returns:
1515
A cleaned string suitable for use as a filename.
1616
"""
17+
# Handle None or empty input
18+
if not name:
19+
return "untitled"
1720
# Replace common punctuation and whitespace with underscores
1821
name = re.sub(r"[\s\-,.:/\\\[\]\(\)]+", "_", name)
1922
# Remove any non-alphanumeric or underscore characters

tests/importers/test_importer_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def test_clean_filename():
2323
# Test with empty string
2424
assert clean_filename("") == "untitled"
2525

26+
# Test with None (fixes #451 - ChatGPT null titles)
27+
assert clean_filename(None) == "untitled"
28+
2629
# Test with only special characters
2730
# Some implementations may return empty string or underscore
2831
result = clean_filename("!@#$%^&*()")

0 commit comments

Comments
 (0)