diff --git a/server/api/themoviedb/personMapper.ts b/server/api/themoviedb/personMapper.ts index d0438e6c..9ee5f930 100644 --- a/server/api/themoviedb/personMapper.ts +++ b/server/api/themoviedb/personMapper.ts @@ -138,7 +138,7 @@ class TmdbPersonMapper extends ExternalAPI { const cleanArtistName = artistName .split(/(?:(?:feat|ft)\.?\s+|&\s*|,\s+)/i)[0] .trim() - .replace(/['']/g, "'"); + .replace(/['′']/g, "'"); const searchResults = await this.get( '/search/person', @@ -151,22 +151,19 @@ class TmdbPersonMapper extends ExternalAPI { this.CACHE_TTL ); - const exactMatches = searchResults.results.filter((person) => { - const normalizedPersonName = person.name + const normalizeName = (name: string): string => { + return name .toLowerCase() .normalize('NFKD') .replace(/[\u0300-\u036f]/g, '') - .replace(/['']/g, "'") + .replace(/['′']/g, "'") .replace(/[^a-z0-9\s]/g, '') .trim(); + }; - const normalizedArtistName = cleanArtistName - .toLowerCase() - .normalize('NFKD') - .replace(/[\u0300-\u036f]/g, '') - .replace(/['']/g, "'") - .replace(/[^a-z0-9\s]/g, '') - .trim(); + const exactMatches = searchResults.results.filter((person) => { + const normalizedPersonName = normalizeName(person.name); + const normalizedArtistName = normalizeName(cleanArtistName); return normalizedPersonName === normalizedArtistName; });