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:
@@ -47,4 +47,13 @@ describe("musicbrainz module", () => {
|
||||
vi.stubGlobal("fetch", vi.fn(() => jsonResponse({ "release-groups": [] })));
|
||||
expect(await searchReleaseGroup("Nobody", "Nothing")).toBeNull();
|
||||
});
|
||||
|
||||
it("escapes quotes in the release-group query", async () => {
|
||||
const fetchMock = vi.fn((_url: string, _init?: RequestInit) => jsonResponse({ "release-groups": [] }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
await searchReleaseGroup("AC/DC", 'Back in "Black"');
|
||||
const [url] = fetchMock.mock.calls[0];
|
||||
// the decoded query must contain the escaped quote, not a bare one that closes the phrase
|
||||
expect(decodeURIComponent(url)).toContain('Back in \\"Black\\"');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user