Skip to content

Commit

Permalink
fix(album-search): 🐛 name_to_initials could throw IndexError when d…
Browse files Browse the repository at this point in the history
…ealing with author using initials

fixes #79
  • Loading branch information
djdembeck committed Feb 23, 2023
1 parent 53b8a9f commit a560848
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Contents/Code/search_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ def name_to_initials(self, input_name):
"""
Converts a name to initials.
Example: 'Arthur Conan Doyle' -> 'A.C.Doyle'
Example: 'J K Rowling' -> 'J.K.Rowling'
Example: 'J. R. R. Tolkien' -> 'J.R.R.Tolkien'
"""
# Shorten input_name by splitting on whitespaces
# Only the surname stays as whole, the rest gets truncated
Expand All @@ -216,7 +218,12 @@ def name_to_initials(self, input_name):
new_name = ""
# Truncate prenames
for part in name_parts[:-1]:
new_name += part[0] + "." if part[1] != "." else part
try:
# Try to get first letter of prename and add dot
new_name += part[0] + "." if part[1] != "." else part
except IndexError:
# If there is only one letter, add dot and return
new_name += part + "." if part != "." else part
# Add surname
new_name += name_parts[-1]

Expand Down

0 comments on commit a560848

Please sign in to comment.