Skip to content

Commit

Permalink
Fix: add spaces when matching author honorifics
Browse files Browse the repository at this point in the history
Matching and stripping honorifics should match `honorific + " "` and not
just `honorific`. Thanks @hornc for catching this!
  • Loading branch information
scottbarnes committed May 22, 2024
1 parent b72499c commit 7e585ed
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions openlibrary/catalog/add_book/load_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,11 @@ def remove_author_honorifics(name: str) -> str:
(
honorific
for honorific in HONORIFICS
if name.casefold().startswith(honorific)
if name.casefold().startswith(f"{honorific} ") # Note the trailing space.
),
None,
):
return name[len(honorific) :].lstrip() or name
return name[len(f"{honorific} ") :].lstrip() or name

return name

Expand Down
1 change: 1 addition & 0 deletions openlibrary/catalog/add_book/tests/test_load_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def add_three_existing_authors(self, mock_site):
@pytest.mark.parametrize(
["name", "expected"],
[
("Drake von Drake", "Drake von Drake"),
("Dr. Seuss", "Dr. Seuss"),
("dr. Seuss", "dr. Seuss"),
("Dr Seuss", "Dr Seuss"),
Expand Down

0 comments on commit 7e585ed

Please sign in to comment.