Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test(citations): pin the title/URL whitespace collapse in the standard formatter (#7547)

Masyarakat AI Indonesia - FMD496f4ed280f0
diff --git a/tests/citation_handlers/test_standard_source_metadata.py b/tests/citation_handlers/test_standard_source_metadata.py
index 20157a0837..d994170c46 100644
--- a/tests/citation_handlers/test_standard_source_metadata.py
+++ b/tests/citation_handlers/test_standard_source_metadata.py
@@ -335,3 +335,38 @@ def test_topic_and_summary_prompts_use_safe_identities_and_numbered_citations():
assert "example-secret" not in prompt
assert source["title"] == 123
assert source["link"].endswith("=example-secret")
+
+
+ ("title", "source", "expected_title", "expected_url"),
+ [
+ (
+ "Spaced out title with runs",
+ "https://example.org/a path?q=1 2",
+ "Spaced out title with runs",
+ "https://example.org/a path?q=1 2",
+ ),
+ (
+ " Leading and trailing ",
+ " https://example.org/padded ",
+ "Leading and trailing",
+ "https://example.org/padded",
+ ),
+ ],
+)
+def test_standard_formatter_collapses_whitespace_in_title_and_url(
+ title, source, expected_title, expected_url
+):
+ """The \" \".join(x.split()) steps keep one identity line per source.
+
+ Without them a whitespace-heavy title or URL reaches the prompt with its
+ interior space runs intact, which reads as garbled identity text.
+ """
+ handler = StandardCitationHandler(Mock())
+ document = Document(
+ page_content="Evidence",
+ metadata={"index": 3, "title": title, "source": source},
+ )
+ assert handler._format_sources([document]) == (
+ f"[3] Title: {expected_title}\nURL: {expected_url}\nContent: Evidence"
+ )