fix(web): escape Lucene quotes in searchReleaseGroup query
A `"` or `\` inside artist/album terminates the quoted Lucene phrase and corrupts the MusicBrainz search query. Escape both terms before interpolation.
This commit is contained in:
@@ -54,8 +54,12 @@ export async function browseReleaseGroups(artistMbid: string): Promise<ReleaseGr
|
||||
return out;
|
||||
}
|
||||
|
||||
function escapeLucenePhrase(s: string): string {
|
||||
return s.replace(/[\\"]/g, (c) => "\\" + c);
|
||||
}
|
||||
|
||||
export async function searchReleaseGroup(artist: string, album: string): Promise<ReleaseGroupMatch | null> {
|
||||
const query = `releasegroup:"${album}" AND artist:"${artist}"`;
|
||||
const query = `releasegroup:"${escapeLucenePhrase(album)}" AND artist:"${escapeLucenePhrase(artist)}"`;
|
||||
const data = await mbGet(`/release-group?query=${encodeURIComponent(query)}&fmt=json&limit=5`);
|
||||
const groups: any[] = data["release-groups"] ?? [];
|
||||
if (groups.length === 0) return null;
|
||||
|
||||
Reference in New Issue
Block a user