diff --git a/routes/document_helpers.py b/routes/document_helpers.py index ebfb177..134157e 100644 --- a/routes/document_helpers.py +++ b/routes/document_helpers.py @@ -203,6 +203,8 @@ def _assert_pdf_marker_upload_owned( def _derive_title(content: str) -> str: """Derive a title from document content.""" import re + if not isinstance(content, str): + return "Untitled" text = content.strip() if not text: return "Untitled" diff --git a/tests/test_derive_title_nonstring.py b/tests/test_derive_title_nonstring.py new file mode 100644 index 0000000..c5b75c7 --- /dev/null +++ b/tests/test_derive_title_nonstring.py @@ -0,0 +1,13 @@ +from routes.document_helpers import _derive_title + + +def test_derive_title_handles_non_string_content(): + # content normally comes from a document text column, but the helper is + # public and a non-string (None / int) made content.strip() raise + # AttributeError instead of falling back to a default title. + assert _derive_title(None) == "Untitled" + assert _derive_title(123) == "Untitled" + + +def test_derive_title_still_reads_markdown_heading(): + assert _derive_title("# Heading Title\nbody text") == "Heading Title"