diff --git a/apps/server/src/answers/answers.test.ts b/apps/server/src/answers/answers.test.ts index a296d9e..0badb70 100644 --- a/apps/server/src/answers/answers.test.ts +++ b/apps/server/src/answers/answers.test.ts @@ -154,3 +154,11 @@ test('플레이리스트 가져오기: the answers come from the title as found expect(job.rows[1]!.title).toBe('밤을 달리다'); expect(job.rows[1]!.titleAnswers).toEqual(expect.arrayContaining(['夜に駆ける', '요루니 카케루', '요루니 가케루'])); }); + +test('a Korean title with a 한자 alias ("몽(夢)") is never renamed, even when Wikipedia knows the 한자', async () => { + const wiki = async (names: string[]) => new Map(names.includes('夢') ? [['夢', '꿈']] : []); + const [a] = await songAnswersBatch(null, [{ title: '몽(夢)', artist: '가수' }], { korean: true, wiki }); + expect(a).toMatchObject({ title: '몽', note: null }); + expect(a!.titleAnswers).toContain('夢'); + expect(a!.titleAnswers).not.toContain('꿈'); +}); diff --git a/apps/server/src/answers/index.ts b/apps/server/src/answers/index.ts index 779a697..b0badbe 100644 --- a/apps/server/src/answers/index.ts +++ b/apps/server/src/answers/index.ts @@ -114,7 +114,9 @@ export async function songAnswersBatch(db: Database | null, songs: { title: stri }; // the Japanese title: shown as is, or already swapped for its bracket's Korean name by cleanTitle // ("夜に駆ける (밤에 달리다)") — Wikipedia still goes first, so the order is decided on the original - const jaTitle = hasJapanese(c.title) ? c.title : c.aliases.find((a) => hasJapanese(a)); + // only when the title outside the brackets was Japanese: "몽(夢)" is a Korean title with a 한자 alias, never renamed + const outsideJa = hasJapanese(s.title.replace(/[([{([【「『][^)\]})]】」』]*[)\]})]】」』]/g, ' ')); + const jaTitle = hasJapanese(c.title) ? c.title : outsideJa ? c.aliases.find((a) => hasJapanese(a)) : undefined; if (opts.korean && jaTitle) { const bracket = hasJapanese(c.title) ? c.aliases.find((a) => HANGUL.test(a) && !hasJapanese(a)) : c.title; title = korean(jaTitle, bracket, extraTitle);