From 7e585ede79d429639f8270d30e8b7bb3b4fddc3d Mon Sep 17 00:00:00 2001 From: Scott Barnes Date: Wed, 22 May 2024 15:49:29 -0700 Subject: [PATCH] Fix: add spaces when matching author honorifics Matching and stripping honorifics should match `honorific + " "` and not just `honorific`. Thanks @hornc for catching this! --- openlibrary/catalog/add_book/load_book.py | 4 ++-- openlibrary/catalog/add_book/tests/test_load_book.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/openlibrary/catalog/add_book/load_book.py b/openlibrary/catalog/add_book/load_book.py index e47cb6e7792..958dcafb952 100644 --- a/openlibrary/catalog/add_book/load_book.py +++ b/openlibrary/catalog/add_book/load_book.py @@ -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 diff --git a/openlibrary/catalog/add_book/tests/test_load_book.py b/openlibrary/catalog/add_book/tests/test_load_book.py index 5948ee23267..f95276283a9 100644 --- a/openlibrary/catalog/add_book/tests/test_load_book.py +++ b/openlibrary/catalog/add_book/tests/test_load_book.py @@ -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"),