Skip to content

Commit 2dad8f1

Browse files
monperrusclaude
andcommitted
Three title normalization fixes
1. @misc colon subtitle: use only the part after ':' when matching web page titles 2. LaTeX escapes: normalize \$ \% \& \# to their plain characters 3. Test corrections and additions for both cases Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bae9c25 commit 2dad8f1

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

check_hallucinations/main.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ def _normalize_title(title):
3232
title.lower()
3333
.strip()
3434
.rstrip(".")
35+
.replace("\\$", "$")
36+
.replace("\\%", "%")
37+
.replace("\\&", "&")
38+
.replace("\\#", "#")
3539
.replace(": ", ". ")
3640
.replace(",", " ")
3741
.replace(" ", " ")
@@ -93,7 +97,9 @@ def check_misc_url(url, bib_title):
9397
page_title = _fetch_page_title(url)
9498
if not page_title:
9599
raise MiscEntryError(f"No <title> found at {url}")
96-
norm_bib = _normalize_title(bib_title)
100+
# When the bib title has a colon, the part after it is the real title
101+
search_title = bib_title.split(":", 1)[1].strip() if ":" in bib_title else bib_title
102+
norm_bib = _normalize_title(search_title)
97103
norm_page = _normalize_title(page_title)
98104
if norm_bib not in norm_page:
99105
raise MiscEntryError(

test_misc.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,23 @@ def test_check_misc_url_no_title(mock_fetch):
3535
mock_fetch.return_value = ""
3636
with pytest.raises(MiscEntryError, match="No <title>"):
3737
check_misc_url("https://example.com", "Some Title")
38+
39+
40+
@patch("check_hallucinations.main._fetch_page_title")
41+
def test_check_misc_url_colon_uses_subtitle(mock_fetch):
42+
# Page shows only the subtitle; the "Main: " prefix is not in the HTML title
43+
mock_fetch.return_value = "The Official Leaderboard | SWE-bench"
44+
check_misc_url(
45+
"https://www.swebench.com",
46+
"SWE-bench: The Official Leaderboard",
47+
)
48+
49+
50+
@patch("check_hallucinations.main._fetch_page_title")
51+
def test_check_misc_url_colon_wrong_subtitle(mock_fetch):
52+
mock_fetch.return_value = "Some Unrelated Page Title"
53+
with pytest.raises(MiscEntryError, match="Title does not match"):
54+
check_misc_url(
55+
"https://example.com",
56+
"My Blog: Adventures in Python",
57+
)

test_normalize.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ def test_diacritics():
1818

1919
def test_curly_braces():
2020
assert _normalize_title("{Foo} Bar") == _normalize_title("Foo Bar")
21+
22+
23+
def test_latex_dollar_escape():
24+
bib = r"Fixing 55 out of 105 bugs for \$8 each"
25+
ss = "Fixing 55 out of 105 bugs for $8 each"
26+
assert _normalize_title(bib) == _normalize_title(ss)

0 commit comments

Comments
 (0)